Subversion Repositories DashDisplay

Rev

Rev 61 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61 Rev 77
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
  ******************************************************************************
3
  * @file    stm32l1xx_hal_opamp.c
3
  * @file    stm32l1xx_hal_opamp.c
4
  * @author  MCD Application Team
4
  * @author  MCD Application Team
5
  * @brief   OPAMP HAL module driver.
5
  * @brief   OPAMP HAL module driver.
6
  *          This file provides firmware functions to manage the following
6
  *          This file provides firmware functions to manage the following
7
  *          functionalities of the operational amplifier(s) peripheral:
7
  *          functionalities of the operational amplifier(s) peripheral:
8
  *           + OPAMP configuration
8
  *           + Initialization and de-initialization functions
9
  *           + OPAMP calibration
9
  *           + IO operation functions
10
  *          Thanks to
10
  *           + Peripheral Control functions
11
  *           + Initialization and de-initialization functions
11
  *           + Peripheral State functions
12
  *           + IO operation functions
12
  *
13
  *           + Peripheral Control functions
13
  ******************************************************************************
14
  *           + Peripheral State functions
14
  * @attention
15
  *        
15
  *
16
  @verbatim
16
  * Copyright (c) 2017 STMicroelectronics.
17
================================================================================
17
  * All rights reserved.
18
          ##### OPAMP Peripheral Features #####
18
  *
19
================================================================================
19
  * This software is licensed under terms that can be found in the LICENSE file
20
  [..] The device integrates up to 3 operational amplifiers OPAMP1, OPAMP2,
20
  * in the root directory of this software component.
21
       OPAMP3 (OPAMP3 availability depends on device category)
21
  * If no LICENSE file comes with this software, it is provided AS-IS.
22
       
22
  *
23
       (#) The OPAMP(s) provide(s) several exclusive running modes.
23
  ******************************************************************************
24
       (++) Standalone mode
24
  @verbatim
25
       (++) Follower mode
25
================================================================================
26
 
26
          ##### OPAMP Peripheral Features #####
27
       (#) All OPAMP (same for all OPAMPs) can operate in
27
================================================================================
28
       (++) Either Low range (VDDA < 2.4V) power supply
28
  [..] The device integrates up to 3 operational amplifiers OPAMP1, OPAMP2,
29
       (++) Or High range (VDDA > 2.4V) power supply
29
       OPAMP3 (OPAMP3 availability depends on device category)
30
 
30
 
31
       (#) Each OPAMP(s) can be configured in normal and low power mode.
31
       (#) The OPAMP(s) provide(s) several exclusive running modes.
32
 
32
       (++) Standalone mode
33
       (#) The OPAMP(s) provide(s) calibration capabilities.  
33
       (++) Follower mode
34
       (++) Calibration aims at correcting some offset for running mode.
34
 
35
       (++) The OPAMP uses either factory calibration settings OR user defined
35
       (#) All OPAMP (same for all OPAMPs) can operate in
36
           calibration (trimming) settings (i.e. trimming mode).
36
       (++) Either Low range (VDDA < 2.4V) power supply
37
       (++) The user defined settings can be figured out using self calibration
37
       (++) Or High range (VDDA > 2.4V) power supply
38
           handled by HAL_OPAMP_SelfCalibrate, HAL_OPAMPEx_SelfCalibrateAll
38
 
39
       (++) HAL_OPAMP_SelfCalibrate:
39
       (#) Each OPAMP(s) can be configured in normal and low power mode.
40
       (+++) Runs automatically the calibration in 2 steps: for transistors
40
 
41
            differential pair high (PMOS) or low (NMOS)
41
       (#) The OPAMP(s) provide(s) calibration capabilities.
42
       (+++) Enables the user trimming mode
42
       (++) Calibration aims at correcting some offset for running mode.
43
       (+++) Updates the init structure with trimming values with fresh calibration
43
       (++) The OPAMP uses either factory calibration settings OR user defined
44
            results.
44
           calibration (trimming) settings (i.e. trimming mode).
45
            The user may store the calibration results for larger
45
       (++) The user defined settings can be figured out using self calibration
46
            (ex monitoring the trimming as a function of temperature
46
           handled by HAL_OPAMP_SelfCalibrate, HAL_OPAMPEx_SelfCalibrateAll
47
            for instance)
47
       (++) HAL_OPAMP_SelfCalibrate:
48
       (+++) For devices having several OPAMPs, HAL_OPAMPEx_SelfCalibrateAll
48
       (+++) Runs automatically the calibration in 2 steps: for transistors
49
            runs calibration of all OPAMPs in parallel to save search time.
49
            differential pair high (PMOS) or low (NMOS)
50
           
50
       (+++) Enables the user trimming mode
51
       (#) Running mode: Standalone mode
51
       (+++) Updates the init structure with trimming values with fresh calibration
52
       (++) Gain is set externally (gain depends on external loads).
52
            results.
53
       (++) Follower mode also possible externally by connecting the inverting input to
53
            The user may store the calibration results for larger
54
           the output.
54
            (ex monitoring the trimming as a function of temperature
55
       
55
            for instance)
56
       (#) Running mode: Follower mode
56
       (+++) For devices having several OPAMPs, HAL_OPAMPEx_SelfCalibrateAll
57
       (++) No Inverting Input is connected.
57
            runs calibration of all OPAMPs in parallel to save search time.
58
       (++) The OPAMP(s) output(s) are internally connected to inverting input.
58
 
59
       
59
       (#) Running mode: Standalone mode
60
            ##### How to use this driver #####
60
       (++) Gain is set externally (gain depends on external loads).
61
================================================================================
61
       (++) Follower mode also possible externally by connecting the inverting input to
62
  [..]
62
           the output.
63
 
63
 
64
    *** Power supply range ***
64
       (#) Running mode: Follower mode
65
    ============================================
65
       (++) No Inverting Input is connected.
66
    [..] To run in low power mode:
66
       (++) The OPAMP(s) output(s) are internally connected to inverting input.
67
 
67
 
68
      (#) Configure the OPAMP using HAL_OPAMP_Init() function:
68
            ##### How to use this driver #####
69
      (++) Select OPAMP_POWERSUPPLY_LOW (VDDA lower than 2.4V)
69
================================================================================
70
      (++) Otherwise select OPAMP_POWERSUPPLY_HIGH (VDDA higher than 2.4V)
70
  [..]
71
 
71
 
72
    *** Low / normal power mode ***
72
    *** Power supply range ***
73
    ============================================
73
    ============================================
74
    [..] To run in low power mode:
74
    [..] To run in low power mode:
75
 
75
 
76
      (#) Configure the OPAMP using HAL_OPAMP_Init() function:
76
      (#) Configure the OPAMP using HAL_OPAMP_Init() function:
77
      (++) Select OPAMP_POWERMODE_LOWPOWER
77
      (++) Select OPAMP_POWERSUPPLY_LOW (VDDA lower than 2.4V)
78
      (++) Otherwise select OPAMP_POWERMODE_NORMAL
78
      (++) Otherwise select OPAMP_POWERSUPPLY_HIGH (VDDA higher than 2.4V)
79
 
79
 
80
    *** Calibration ***
80
    *** Low / normal power mode ***
81
    ============================================
81
    ============================================
82
    [..] To run the OPAMP calibration self calibration:
82
    [..] To run in low power mode:
83
 
83
 
84
      (#) Start calibration using HAL_OPAMP_SelfCalibrate.
84
      (#) Configure the OPAMP using HAL_OPAMP_Init() function:
85
           Store the calibration results.
85
      (++) Select OPAMP_POWERMODE_LOWPOWER
86
 
86
      (++) Otherwise select OPAMP_POWERMODE_NORMAL
87
    *** Running mode ***
87
 
88
    ============================================
88
    *** Calibration ***
89
     
89
    ============================================
90
    [..] To use the OPAMP, perform the following steps:
90
    [..] To run the OPAMP calibration self calibration:
91
           
91
 
92
      (#) Fill in the HAL_OPAMP_MspInit() to
92
      (#) Start calibration using HAL_OPAMP_SelfCalibrate.
93
      (++) Enable the OPAMP Peripheral clock using macro __HAL_RCC_OPAMP_CLK_ENABLE()
93
           Store the calibration results.
94
      (++) Configure the OPAMP input AND output in analog mode using
94
 
95
           HAL_GPIO_Init() to map the OPAMP output to the GPIO pin.
95
    *** Running mode ***
96
 
96
    ============================================
97
      (#) Registrate Callbacks
97
 
98
      (++) The compilation define  USE_HAL_OPAMP_REGISTER_CALLBACKS when set to 1
98
    [..] To use the OPAMP, perform the following steps:
99
           allows the user to configure dynamically the driver callbacks.
99
 
100
 
100
      (#) Fill in the HAL_OPAMP_MspInit() to
101
      (++) Use Functions @ref HAL_OPAMP_RegisterCallback() to register a user callback,
101
      (++) Enable the OPAMP Peripheral clock using macro __HAL_RCC_OPAMP_CLK_ENABLE()
102
           it allows to register following callbacks:
102
      (++) Configure the OPAMP input AND output in analog mode using
103
      (+++) MspInitCallback         : OPAMP MspInit.
103
           HAL_GPIO_Init() to map the OPAMP output to the GPIO pin.
104
      (+++) MspDeInitCallback       : OPAMP MspFeInit.
104
 
105
           This function takes as parameters the HAL peripheral handle, the Callback ID
105
      (#) Registrate Callbacks
106
           and a pointer to the user callback function.
106
      (++) The compilation define  USE_HAL_OPAMP_REGISTER_CALLBACKS when set to 1
107
 
107
           allows the user to configure dynamically the driver callbacks.
108
      (++) Use function @ref HAL_OPAMP_UnRegisterCallback() to reset a callback to the default
108
 
109
           weak (surcharged) function. It allows to reset following callbacks:
109
      (++) Use Functions HAL_OPAMP_RegisterCallback() to register a user callback,
110
      (+++) MspInitCallback         : OPAMP MspInit.
110
           it allows to register following callbacks:
111
      (+++) MspDeInitCallback       : OPAMP MspdeInit.
111
      (+++) MspInitCallback         : OPAMP MspInit.
112
      (+++) All Callbacks
112
      (+++) MspDeInitCallback       : OPAMP MspFeInit.
113
 
113
           This function takes as parameters the HAL peripheral handle, the Callback ID
114
      (#) Configure the OPAMP using HAL_OPAMP_Init() function:
114
           and a pointer to the user callback function.
115
      (++) Select the mode
115
 
116
      (++) Select the inverting input
116
      (++) Use function HAL_OPAMP_UnRegisterCallback() to reset a callback to the default
117
      (++) Select the non-inverting input
117
           weak (overridden) function. It allows to reset following callbacks:
118
      (++) Select either factory or user defined trimming mode.
118
      (+++) MspInitCallback         : OPAMP MspInit.
119
      (++) If the user-defined trimming mode is enabled, select PMOS & NMOS trimming values
119
      (+++) MspDeInitCallback       : OPAMP MspdeInit.
120
          (typically values set by HAL_OPAMP_SelfCalibrate function).
120
      (+++) All Callbacks
121
     
121
 
122
      (#) Enable the OPAMP using HAL_OPAMP_Start() function.
122
      (#) Configure the OPAMP using HAL_OPAMP_Init() function:
123
           
123
      (++) Select the mode
124
      (#) Disable the OPAMP using HAL_OPAMP_Stop() function.
124
      (++) Select the inverting input
125
     
125
      (++) Select the non-inverting input
126
      (#) Lock the OPAMP in running mode using HAL_OPAMP_Lock() function.
126
      (++) Select either factory or user defined trimming mode.
127
          Caution: On STM32L1, HAL OPAMP lock is software lock only (not
127
      (++) If the user-defined trimming mode is enabled, select PMOS & NMOS trimming values
128
          hardware lock as on some other STM32 devices)
128
          (typically values set by HAL_OPAMP_SelfCalibrate function).
129
 
129
 
130
      (#) If needed, unlock the OPAMP using HAL_OPAMPEx_Unlock() function.
130
      (#) Enable the OPAMP using HAL_OPAMP_Start() function.
131
 
131
 
132
    *** Running mode: change of configuration while OPAMP ON  ***
132
      (#) Disable the OPAMP using HAL_OPAMP_Stop() function.
133
    ============================================
133
 
134
    [..] To Re-configure OPAMP when OPAMP is ON (change on the fly)
134
      (#) Lock the OPAMP in running mode using HAL_OPAMP_Lock() function.
135
      (#) If needed, fill in the HAL_OPAMP_MspInit()
135
          Caution: On STM32L1, HAL OPAMP lock is software lock only (not
136
      (++) This is the case for instance if you wish to use new OPAMP I/O
136
          hardware lock as on some other STM32 devices)
137
 
137
 
138
      (#) Configure the OPAMP using HAL_OPAMP_Init() function:
138
      (#) If needed, unlock the OPAMP using HAL_OPAMPEx_Unlock() function.
139
      (++) As in configure case, select first the parameters you wish to modify.
139
 
140
     
140
    *** Running mode: change of configuration while OPAMP ON  ***
141
      (#) Change from low power mode to normal power mode (& vice versa) requires  
141
    ============================================
142
          first HAL_OPAMP_DeInit() (force OPAMP OFF) and then HAL_OPAMP_Init().
142
    [..] To Re-configure OPAMP when OPAMP is ON (change on the fly)
143
          In other words, of OPAMP is ON, HAL_OPAMP_Init can NOT change power mode
143
      (#) If needed, fill in the HAL_OPAMP_MspInit()
144
          alone.
144
      (++) This is the case for instance if you wish to use new OPAMP I/O
145
 
145
 
146
  @endverbatim
146
      (#) Configure the OPAMP using HAL_OPAMP_Init() function:
147
  ******************************************************************************
147
      (++) As in configure case, select first the parameters you wish to modify.
148
  * @attention
148
 
149
  *
149
      (#) Change from low power mode to normal power mode (& vice versa) requires
150
  * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
150
          first HAL_OPAMP_DeInit() (force OPAMP OFF) and then HAL_OPAMP_Init().
151
  * All rights reserved.</center></h2>
151
          In other words, of OPAMP is ON, HAL_OPAMP_Init can NOT change power mode
152
  *
152
          alone.
153
  * This software component is licensed by ST under BSD 3-Clause license,
153
 
154
  * the "License"; You may not use this file except in compliance with the
154
  @endverbatim
155
  * License. You may obtain a copy of the License at:
155
  ******************************************************************************
156
  *                        opensource.org/licenses/BSD-3-Clause
156
  */
157
  *
157
 
158
  ******************************************************************************  
158
/*
159
  */
159
  Additional remark:
160
 
160
    The OPAMPs inverting input can be selected among the list shown by table below.
161
/*
161
    The OPAMPs non inverting input can be selected among the list shown by table below.
162
  Additionnal remark:
162
 
163
    The OPAMPs inverting input can be selected among the list shown by table below.
163
    Table 1.  OPAMPs inverting/non-inverting inputs for STM32L1 devices:
164
    The OPAMPs non inverting input can be selected among the list shown by table below.
164
    +--------------------------------------------------------------------------+
165
       
165
    |                | HAL param  |    OPAMP1    |    OPAMP2    |   OPAMP3(4)  |
166
    Table 1.  OPAMPs inverting/non-inverting inputs for STM32L1 devices:
166
    |                |   name     |              |              |              |
167
    +--------------------------------------------------------------------------+
167
    |----------------|------------|--------------|--------------|--------------|
168
    |                | HAL param  |    OPAMP1    |    OPAMP2    |   OPAMP3(4)  |
168
    |   Inverting    |    VM0     |     PA2      |     PA7      |     PC2      |
169
    |                |   name     |              |              |              |
169
    |    input (1)   |    VM1     | VINM pin (2) | VINM pin (2) | VINM pin (2) |
170
    |----------------|------------|--------------|--------------|--------------|
170
    |----------------|------------|--------------|--------------|--------------|
171
    |   Inverting    |    VM0     |     PA2      |     PA7      |     PC2      |
171
    |  Non Inverting |    VP0     |     PA1      |     PA6      |     PC1      |
172
    |    input (1)   |    VM1     | VINM pin (2) | VINM pin (2) | VINM pin (2) |
172
    |    input       | DAC_CH1 (3)|   DAC_CH1    |   DAC_CH1    |     ---      |
173
    |----------------|------------|--------------|--------------|--------------|
173
    |                | DAC_CH2 (3)|     ---      |   DAC_CH2    |   DAC_CH2    |
174
    |  Non Inverting |    VP0     |     PA1      |     PA6      |     PC1      |
174
    +--------------------------------------------------------------------------+
175
    |    input       | DAC_CH1 (3)|   DAC_CH1    |   DAC_CH1    |     ---      |
175
    (1): NA in follower mode.
176
    |                | DAC_CH2 (3)|     ---      |   DAC_CH2    |   DAC_CH2    |
176
    (2): OPAMP input OPAMPx_VINM are dedicated OPAMP pins, their availability
177
    +--------------------------------------------------------------------------+
177
         depends on device package.
178
    (1): NA in follower mode.
178
    (3): DAC channels 1 and 2 are connected internally to OPAMP. Nevertheless,
179
    (2): OPAMP input OPAMPx_VINM are dedicated OPAMP pins, their availability
179
         I/O pins connected to DAC can still be used as DAC output (pins PA4
180
         depends on device package.
180
         and PA5).
181
    (3): DAC channels 1 and 2 are connected internally to OPAMP. Nevertheless,
181
    (4): OPAMP3 availability depends on device category.
182
         I/O pins connected to DAC can still be used as DAC output (pins PA4
182
 
183
         and PA5).
183
    Table 2.  OPAMPs outputs for STM32L1 devices:
184
    (4): OPAMP3 availability depends on device category.
184
    +--------------------------------------------------------+
185
 
185
    |                 |   OPAMP1   |   OPAMP2   |  OPAMP3(4) |
186
    Table 2.  OPAMPs outputs for STM32L1 devices:
186
    |-----------------|------------|------------|------------|
187
    +--------------------------------------------------------+
187
    | Output          |    PA3     |    PB0     |    PC3     |
188
    |                 |   OPAMP1   |   OPAMP2   |  OPAMP3(4) |
188
    +--------------------------------------------------------+
189
    |-----------------|------------|------------|------------|
189
    (4) : OPAMP3 availability depends on device category
190
    | Output          |    PA3     |    PB0     |    PC3     |
190
*/
191
    +--------------------------------------------------------+
191
 
192
    (4) : OPAMP3 availability depends on device category
192
/* Includes ------------------------------------------------------------------*/
193
*/
193
#include "stm32l1xx_hal.h"
194
 
194
 
195
/* Includes ------------------------------------------------------------------*/
195
/** @addtogroup STM32L1xx_HAL_Driver
196
#include "stm32l1xx_hal.h"
196
  * @{
197
   
197
  */
198
/** @addtogroup STM32L1xx_HAL_Driver
198
 
199
  * @{
199
/** @defgroup OPAMP OPAMP
200
  */
200
  * @brief OPAMP module driver
201
 
201
  * @{
202
/** @defgroup OPAMP OPAMP
202
  */
203
  * @brief OPAMP module driver
203
 
204
  * @{
204
#ifdef HAL_OPAMP_MODULE_ENABLED
205
  */
205
 
206
 
206
#if defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L151xE) || defined (STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) || defined (STM32L162xC) || defined (STM32L152xC) || defined (STM32L151xC)
207
#ifdef HAL_OPAMP_MODULE_ENABLED
207
 
208
 
208
/* Private typedef -----------------------------------------------------------*/
209
#if defined (STM32L151xCA) || defined (STM32L151xD) || defined (STM32L152xCA) || defined (STM32L152xD) || defined (STM32L162xCA) || defined (STM32L162xD) || defined (STM32L151xE) || defined (STM32L151xDX) || defined (STM32L152xE) || defined (STM32L152xDX) || defined (STM32L162xE) || defined (STM32L162xDX) || defined (STM32L162xC) || defined (STM32L152xC) || defined (STM32L151xC)
209
/* Private define ------------------------------------------------------------*/
210
 
210
/* Private macro -------------------------------------------------------------*/
211
/* Private typedef -----------------------------------------------------------*/
211
/* Private variables ---------------------------------------------------------*/
212
/* Private define ------------------------------------------------------------*/
212
/* Private constants ---------------------------------------------------------*/
213
/* Private macro -------------------------------------------------------------*/
213
/* Private function prototypes -----------------------------------------------*/
214
/* Private variables ---------------------------------------------------------*/
214
/* Private functions ---------------------------------------------------------*/
215
/* Private constants ---------------------------------------------------------*/
215
/* Exported functions --------------------------------------------------------*/
216
/* Private function prototypes -----------------------------------------------*/
216
 
217
/* Private functions ---------------------------------------------------------*/
217
/** @defgroup OPAMP_Exported_Functions OPAMP Exported Functions
218
/* Exported functions --------------------------------------------------------*/
218
  * @{
219
 
219
  */
220
/** @defgroup OPAMP_Exported_Functions OPAMP Exported Functions
220
 
221
  * @{
221
/** @defgroup OPAMP_Exported_Functions_Group1 Initialization and de-initialization functions
222
  */
222
 *  @brief    Initialization and Configuration functions
223
 
223
 *
224
/** @defgroup OPAMP_Exported_Functions_Group1 Initialization and de-initialization functions
224
@verbatim
225
 *  @brief    Initialization and Configuration functions
225
  ==============================================================================
226
 *
226
              ##### Initialization and de-initialization functions #####
227
@verbatim    
227
  ==============================================================================
228
  ==============================================================================
228
   [..]  This section provides functions allowing to:
229
              ##### Initialization and de-initialization functions #####
229
 
230
  ==============================================================================
230
@endverbatim
231
   [..]  This section provides functions allowing to:
231
  * @{
232
 
232
  */
233
@endverbatim
233
 
234
  * @{
234
/**
235
  */
235
  * @brief  Initializes the OPAMP according to the specified
236
 
236
  *         parameters in the OPAMP_InitTypeDef and create the associated handle.
237
/**
237
  * @note   If the selected opamp is locked, initialization can't be performed.
238
  * @brief  Initializes the OPAMP according to the specified
238
  *         To unlock the configuration, perform a system reset.
239
  *         parameters in the OPAMP_InitTypeDef and create the associated handle.
239
  * @param  hopamp OPAMP handle
240
  * @note   If the selected opamp is locked, initialization can't be performed.
240
  * @retval HAL status
241
  *         To unlock the configuration, perform a system reset.
241
  */
242
  * @param  hopamp OPAMP handle
242
HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef* hopamp)
243
  * @retval HAL status
243
{
244
  */
244
  HAL_StatusTypeDef status = HAL_OK;
245
HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef* hopamp)
245
  uint32_t tmp_csr;       /* Temporary variable to update register CSR, except bits ANAWSSELx, S7SEL2, OPA_RANGE, OPAxCALOUT */
246
{
246
 
247
  HAL_StatusTypeDef status = HAL_OK;
247
  /* Check the OPAMP handle allocation and lock status */
248
  uint32_t tmp_csr;       /* Temporary variable to update register CSR, except bits ANAWSSELx, S7SEL2, OPA_RANGE, OPAxCALOUT */
248
  /* Init not allowed if calibration is ongoing */
249
 
249
  if(hopamp == NULL)
250
  /* Check the OPAMP handle allocation and lock status */
250
  {
251
  /* Init not allowed if calibration is ongoing */
251
    return HAL_ERROR;
252
  if(hopamp == NULL)
252
  }
253
  {
253
  else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
254
    return HAL_ERROR;
254
  {
255
  }
255
    return HAL_ERROR;
256
  else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
256
  }
257
  {
257
  else if(hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
258
    return HAL_ERROR;
258
  {
259
  }
259
    return HAL_ERROR;
260
  else if(hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
260
  }
261
  {
261
  else
262
    return HAL_ERROR;
262
  {
263
  }
263
    /* Check the parameter */
264
  else
264
    assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
265
  {
265
 
266
    /* Check the parameter */
266
    /* Set OPAMP parameters */
267
    assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
267
    assert_param(IS_OPAMP_POWER_SUPPLY_RANGE(hopamp->Init.PowerSupplyRange));
268
       
268
    assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
269
    /* Set OPAMP parameters */
269
    assert_param(IS_OPAMP_FUNCTIONAL_NORMALMODE(hopamp->Init.Mode));
270
    assert_param(IS_OPAMP_POWER_SUPPLY_RANGE(hopamp->Init.PowerSupplyRange));
270
    assert_param(IS_OPAMP_NONINVERTING_INPUT_CHECK_INSTANCE(hopamp, hopamp->Init.NonInvertingInput));
271
    assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
271
    assert_param(IS_OPAMP_TRIMMING(hopamp->Init.UserTrimming));
272
    assert_param(IS_OPAMP_FUNCTIONAL_NORMALMODE(hopamp->Init.Mode));
272
 
273
    assert_param(IS_OPAMP_NONINVERTING_INPUT_CHECK_INSTANCE(hopamp, hopamp->Init.NonInvertingInput));
273
#if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
274
    assert_param(IS_OPAMP_TRIMMING(hopamp->Init.UserTrimming));
274
    if(hopamp->State == HAL_OPAMP_STATE_RESET)
275
 
275
    {
276
#if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
276
      if(hopamp->MspInitCallback == NULL)
277
    if(hopamp->State == HAL_OPAMP_STATE_RESET)
277
      {
278
    {
278
        hopamp->MspInitCallback               = HAL_OPAMP_MspInit;
279
      if(hopamp->MspInitCallback == NULL)
279
      }
280
      {
280
    }
281
        hopamp->MspInitCallback               = HAL_OPAMP_MspInit;
281
#endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
282
      }
282
 
283
    }
283
    if (hopamp->Init.Mode != OPAMP_FOLLOWER_MODE)
284
#endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
284
    {
285
 
285
      assert_param(IS_OPAMP_INVERTING_INPUT(hopamp->Init.InvertingInput));
286
    if (hopamp->Init.Mode != OPAMP_FOLLOWER_MODE)
286
    }
287
    {
287
 
288
      assert_param(IS_OPAMP_INVERTING_INPUT(hopamp->Init.InvertingInput));
288
    if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
289
    }
289
    {
290
   
290
      if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
291
    if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
291
      {
292
    {
292
        assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueP));
293
      if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
293
        assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueN));
294
      {
294
      }
295
        assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueP));
295
      else
296
        assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueN));
296
      {
297
      }
297
        assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValuePLowPower));
298
      else
298
        assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueNLowPower));
299
      {
299
      }
300
        assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValuePLowPower));
300
    }
301
        assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueNLowPower));
301
 
302
      }
302
    if(hopamp->State == HAL_OPAMP_STATE_RESET)
303
    }
303
    {
304
   
304
      /* Allocate lock resource and initialize it */
305
    if(hopamp->State == HAL_OPAMP_STATE_RESET)
305
      hopamp->Lock = HAL_UNLOCKED;
306
    {
306
    }
307
      /* Allocate lock resource and initialize it */
307
 
308
      hopamp->Lock = HAL_UNLOCKED;
308
#if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
309
    }
309
    hopamp->MspInitCallback(hopamp);
310
 
310
#else
311
#if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
311
    /* Call MSP init function */
312
    hopamp->MspInitCallback(hopamp);    
312
    HAL_OPAMP_MspInit(hopamp);
313
#else
313
#endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
314
    /* Call MSP init function */
314
 
315
    HAL_OPAMP_MspInit(hopamp);
315
    /* Set OPAMP parameters                                                   */
316
#endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
316
    /* - Set internal switches in function of:                                */
317
 
317
    /*   - OPAMP selected mode: standalone or follower.                       */
318
    /* Set OPAMP parameters                                                   */
318
    /*   - Non-inverting input connection                                     */
319
    /* - Set internal switches in function of:                                */
319
    /*   - Inverting input connection                                         */
320
    /*   - OPAMP selected mode: standalone or follower.                       */
320
    /* - Set power supply range                                               */
321
    /*   - Non-inverting input connection                                     */
321
    /* - Set power mode and associated calibration parameters                 */
322
    /*   - Inverting input connection                                         */
322
 
323
    /* - Set power supply range                                               */
323
    /* Get OPAMP CSR register into temporary variable */
324
    /* - Set power mode and associated calibration parameters                 */
324
    /* Note: OPAMP register CSR is written directly, independently of OPAMP   */
325
   
325
    /*       instance, because all OPAMP settings are dispatched in the same  */
326
    /* Get OPAMP CSR register into temporary variable */
326
    /*       register.                                                        */
327
    /* Note: OPAMP register CSR is written directly, independently of OPAMP   */
327
    /*       Settings of bits for each OPAMP instances are managed case by    */
328
    /*       instance, because all OPAMP settings are dispatched in the same  */
328
    /*       case using macro (OPAMP_CSR_S3SELX(), OPAMP_CSR_ANAWSELX(), ...) */
329
    /*       register.                                                        */
329
    tmp_csr = OPAMP->CSR;
330
    /*       Settings of bits for each OPAMP instances are managed case by    */
330
 
331
    /*       case using macro (OPAMP_CSR_S3SELX(), OPAMP_CSR_ANAWSELX(), ...) */
331
    /* Open all switches on non-inverting input, inverting input and output   */
332
    tmp_csr = OPAMP->CSR;
332
    /* feedback.                                                              */
333
   
333
    CLEAR_BIT(tmp_csr, OPAMP_CSR_ALL_SWITCHES(hopamp));
334
    /* Open all switches on non-inverting input, inverting input and output   */
334
 
335
    /* feedback.                                                              */
335
    /* Set internal switches in function of OPAMP mode selected: standalone   */
336
    CLEAR_BIT(tmp_csr, OPAMP_CSR_ALL_SWITCHES(hopamp));
336
    /* or follower.                                                           */
337
   
337
    /* If follower mode is selected, feedback switch S3 is closed and         */
338
    /* Set internal switches in function of OPAMP mode selected: standalone   */
338
    /* inverting inputs switches are let opened.                              */
339
    /* or follower.                                                           */
339
    /* If standalone mode is selected, feedback switch S3 is let opened and   */
340
    /* If follower mode is selected, feedback switch S3 is closed and         */
340
    /* the selected inverting inputs switch is closed.                        */
341
    /* inverting inputs switches are let opened.                              */
341
    if (hopamp->Init.Mode == OPAMP_FOLLOWER_MODE)
342
    /* If standalone mode is selected, feedback switch S3 is let opened and   */
342
    {
343
    /* the selected inverting inputs switch is closed.                        */
343
      /* Follower mode: Close switches S3 and SanB */
344
    if (hopamp->Init.Mode == OPAMP_FOLLOWER_MODE)
344
      SET_BIT(tmp_csr, OPAMP_CSR_S3SELX(hopamp));
345
    {
345
    }
346
      /* Follower mode: Close switches S3 and SanB */
346
    else
347
      SET_BIT(tmp_csr, OPAMP_CSR_S3SELX(hopamp));
347
    {
348
    }
348
      /* Set internal switches in function of inverting input selected:       */
349
    else
349
      /* Close switch to connect OPAMP inverting input to the selected        */
350
    {
350
      /* input: dedicated IO pin or alternative IO pin available on some      */
351
      /* Set internal switches in function of inverting input selected:       */
351
      /* device packages.                                                     */
352
      /* Close switch to connect OPAMP inverting input to the selected        */
352
      if (hopamp->Init.InvertingInput == OPAMP_INVERTINGINPUT_IO0)
353
      /* input: dedicated IO pin or alternative IO pin available on some      */
353
      {
354
      /* device packages.                                                     */
354
        /* Close switch to connect OPAMP non-inverting input to               */
355
      if (hopamp->Init.InvertingInput == OPAMP_INVERTINGINPUT_IO0)
355
        /* dedicated IO pin low-leakage.                                      */
356
      {
356
        SET_BIT(tmp_csr, OPAMP_CSR_S4SELX(hopamp));
357
        /* Close switch to connect OPAMP non-inverting input to               */
357
      }
358
        /* dedicated IO pin low-leakage.                                      */
358
      else
359
        SET_BIT(tmp_csr, OPAMP_CSR_S4SELX(hopamp));
359
      {
360
      }
360
        /* Close switch to connect OPAMP inverting input to alternative       */
361
      else
361
        /* IO pin available on some device packages.                          */
362
      {
362
        SET_BIT(tmp_csr, OPAMP_CSR_ANAWSELX(hopamp));
363
        /* Close switch to connect OPAMP inverting input to alternative       */
363
      }
364
        /* IO pin available on some device packages.                          */
364
    }
365
        SET_BIT(tmp_csr, OPAMP_CSR_ANAWSELX(hopamp));
365
 
366
      }
366
    /* Set internal switches in function of non-inverting input selected:     */
367
    }
367
    /* Close switch to connect OPAMP non-inverting input to the selected      */
368
   
368
    /* input: dedicated IO pin or DAC channel.                                */
369
    /* Set internal switches in function of non-inverting input selected:     */
369
    if (hopamp->Init.NonInvertingInput == OPAMP_NONINVERTINGINPUT_IO0)
370
    /* Close switch to connect OPAMP non-inverting input to the selected      */
370
    {
371
    /* input: dedicated IO pin or DAC channel.                                */
371
      /* Close switch to connect OPAMP non-inverting input to                 */
372
    if (hopamp->Init.NonInvertingInput == OPAMP_NONINVERTINGINPUT_IO0)
372
      /* dedicated IO pin low-leakage.                                        */
373
    {
373
      SET_BIT(tmp_csr, OPAMP_CSR_S5SELX(hopamp));
374
      /* Close switch to connect OPAMP non-inverting input to                 */
374
    }
375
      /* dedicated IO pin low-leakage.                                        */
375
    else if (hopamp->Init.NonInvertingInput == OPAMP_NONINVERTINGINPUT_DAC_CH1)
376
      SET_BIT(tmp_csr, OPAMP_CSR_S5SELX(hopamp));
376
    {
377
    }
377
 
378
    else if (hopamp->Init.NonInvertingInput == OPAMP_NONINVERTINGINPUT_DAC_CH1)
378
      /* Particular case for connection to DAC channel 1:                     */
379
    {
379
      /* OPAMP_NONINVERTINGINPUT_DAC_CH1 available on OPAMP1 and OPAMP2 only  */
380
     
380
      /* (OPAMP3 availability depends on device category).                    */
381
      /* Particular case for connection to DAC channel 1:                     */
381
      if ((hopamp->Instance == OPAMP1) || (hopamp->Instance == OPAMP2))
382
      /* OPAMP_NONINVERTINGINPUT_DAC_CH1 available on OPAMP1 and OPAMP2 only  */
382
      {
383
      /* (OPAMP3 availability depends on device category).                    */
383
        /* Close switch to connect OPAMP non-inverting input to               */
384
      if ((hopamp->Instance == OPAMP1) || (hopamp->Instance == OPAMP2))
384
        /* DAC channel 1.                                                     */
385
      {
385
        SET_BIT(tmp_csr, OPAMP_CSR_S6SELX(hopamp));
386
        /* Close switch to connect OPAMP non-inverting input to               */
386
      }
387
        /* DAC channel 1.                                                     */
387
      else
388
        SET_BIT(tmp_csr, OPAMP_CSR_S6SELX(hopamp));
388
      {
389
      }
389
        /* Set HAL status to error if another OPAMP instance as OPAMP1 or     */
390
      else
390
        /* OPAMP2 is intended to be connected to DAC channel 2.               */
391
      {
391
        status = HAL_ERROR;
392
        /* Set HAL status to error if another OPAMP instance as OPAMP1 or     */
392
      }
393
        /* OPAMP2 is intended to be connected to DAC channel 2.               */
393
    }
394
        status = HAL_ERROR;
394
    else /* if (hopamp->Init.NonInvertingInput ==                             */
395
      }
395
         /*     OPAMP_NONINVERTINGINPUT_DAC_CH2  )                            */
396
    }
396
    {
397
    else /* if (hopamp->Init.NonInvertingInput ==                             */
397
      /* Particular case for connection to DAC channel 2:                     */
398
         /*     OPAMP_NONINVERTINGINPUT_DAC_CH2  )                            */
398
      /* OPAMP_NONINVERTINGINPUT_DAC_CH2 available on OPAMP2 and OPAMP3 only  */
399
    {
399
      /* (OPAMP3 availability depends on device category).                    */
400
      /* Particular case for connection to DAC channel 2:                     */
400
      if (hopamp->Instance == OPAMP2)
401
      /* OPAMP_NONINVERTINGINPUT_DAC_CH2 available on OPAMP2 and OPAMP3 only  */
401
      {
402
      /* (OPAMP3 availability depends on device category).                    */
402
        /* Close switch to connect OPAMP non-inverting input to               */
403
      if (hopamp->Instance == OPAMP2)
403
        /* DAC channel 2.                                                     */
404
      {
404
        SET_BIT(tmp_csr, OPAMP_CSR_S7SEL2);
405
        /* Close switch to connect OPAMP non-inverting input to               */
405
      }
406
        /* DAC channel 2.                                                     */
406
      /* If OPAMP3 is selected (if available) */
407
        SET_BIT(tmp_csr, OPAMP_CSR_S7SEL2);
407
      else if (hopamp->Instance != OPAMP1)
408
      }
408
      {
409
      /* If OPAMP3 is selected (if available) */
409
        /* Close switch to connect OPAMP non-inverting input to               */
410
      else if (hopamp->Instance != OPAMP1)
410
        /* DAC channel 2.                                                     */
411
      {
411
        SET_BIT(tmp_csr, OPAMP_CSR_S6SELX(hopamp));
412
        /* Close switch to connect OPAMP non-inverting input to               */
412
      }
413
        /* DAC channel 2.                                                     */
413
      else
414
        SET_BIT(tmp_csr, OPAMP_CSR_S6SELX(hopamp));
414
      {
415
      }
415
        /* Set HAL status to error if another OPAMP instance as OPAMP2 or     */
416
      else
416
        /* OPAMP3 (if available) is intended to be connected to DAC channel 2.*/
417
      {
417
        status = HAL_ERROR;
418
        /* Set HAL status to error if another OPAMP instance as OPAMP2 or     */
418
      }
419
        /* OPAMP3 (if available) is intended to be connected to DAC channel 2.*/
419
    }
420
        status = HAL_ERROR;
420
 
421
      }
421
    /* Continue OPAMP configuration if settings of switches are correct */
422
    }
422
    if (status != HAL_ERROR)
423
   
423
    {
424
    /* Continue OPAMP configuration if settings of switches are correct */
424
      /* Set power mode and associated calibration parameters */
425
    if (status != HAL_ERROR)
425
      if (hopamp->Init.PowerMode != OPAMP_POWERMODE_LOWPOWER)
426
    {
426
      {
427
      /* Set power mode and associated calibration parameters */
427
        /* Set normal mode */
428
      if (hopamp->Init.PowerMode != OPAMP_POWERMODE_LOWPOWER)
428
        CLEAR_BIT(tmp_csr, OPAMP_CSR_OPAXLPM(hopamp));
429
      {
429
 
430
        /* Set normal mode */
430
        if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
431
        CLEAR_BIT(tmp_csr, OPAMP_CSR_OPAXLPM(hopamp));
431
        {
432
       
432
          /* Set calibration mode (factory or user) and values for            */
433
        if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
433
          /* transistors differential pair high (PMOS) and low (NMOS) for     */
434
        {
434
          /* normal mode.                                                     */
435
          /* Set calibration mode (factory or user) and values for            */
435
          MODIFY_REG(OPAMP->OTR, OPAMP_OTR_OT_USER                                                                     |
436
          /* transistors differential pair high (PMOS) and low (NMOS) for     */
436
                                 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_N, OPAMP_TRIM_VALUE_MASK)       |
437
          /* normal mode.                                                     */
437
                                 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_P, OPAMP_TRIM_VALUE_MASK)        ,
438
          MODIFY_REG(OPAMP->OTR, OPAMP_OTR_OT_USER                                                                     |
438
                                 hopamp->Init.UserTrimming                                                             |
439
                                 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_N, OPAMP_TRIM_VALUE_MASK)       |
439
                                 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_N, hopamp->Init.TrimmingValueN) |
440
                                 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_P, OPAMP_TRIM_VALUE_MASK)        ,
440
                                 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_P, hopamp->Init.TrimmingValueP)  );
441
                                 hopamp->Init.UserTrimming                                                             |
441
        }
442
                                 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_N, hopamp->Init.TrimmingValueN) |
442
        else
443
                                 OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_P, hopamp->Init.TrimmingValueP)  );
443
        {
444
        }
444
          /* Set calibration mode to factory */
445
        else
445
          CLEAR_BIT(OPAMP->OTR, OPAMP_OTR_OT_USER);
446
        {
446
        }
447
          /* Set calibration mode to factory */
447
 
448
          CLEAR_BIT(OPAMP->OTR, OPAMP_OTR_OT_USER);
448
      }
449
        }
449
      else
450
       
450
      {
451
      }
451
        /* Set low power mode */
452
      else
452
        SET_BIT(tmp_csr, OPAMP_CSR_OPAXLPM(hopamp));
453
      {
453
 
454
        /* Set low power mode */
454
        if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
455
        SET_BIT(tmp_csr, OPAMP_CSR_OPAXLPM(hopamp));
455
        {
456
       
456
          /* Set calibration mode to user trimming */
457
        if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
457
          SET_BIT(OPAMP->OTR, OPAMP_OTR_OT_USER);
458
        {
458
 
459
          /* Set calibration mode to user trimming */
459
          /* Set values for transistors differential pair high (PMOS) and low */
460
          SET_BIT(OPAMP->OTR, OPAMP_OTR_OT_USER);
460
          /* (NMOS) for low power mode.                                       */
461
         
461
          MODIFY_REG(OPAMP->LPOTR, OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_N, OPAMP_TRIM_VALUE_MASK)               |
462
          /* Set values for transistors differential pair high (PMOS) and low */
462
                                   OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_P, OPAMP_TRIM_VALUE_MASK)                ,
463
          /* (NMOS) for low power mode.                                       */
463
                                   OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_N, hopamp->Init.TrimmingValueNLowPower) |
464
          MODIFY_REG(OPAMP->LPOTR, OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_N, OPAMP_TRIM_VALUE_MASK)               |
464
                                   OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_P, hopamp->Init.TrimmingValuePLowPower)  );
465
                                   OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_P, OPAMP_TRIM_VALUE_MASK)                ,
465
        }
466
                                   OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_N, hopamp->Init.TrimmingValueNLowPower) |
466
        else
467
                                   OPAMP_OFFSET_TRIM_SET(hopamp, OPAMP_FACTORYTRIMMING_P, hopamp->Init.TrimmingValuePLowPower)  );
467
        {
468
        }
468
          /* Set calibration mode to factory trimming */
469
        else
469
          CLEAR_BIT(OPAMP->OTR, OPAMP_OTR_OT_USER);
470
        {
470
        }
471
          /* Set calibration mode to factory trimming */
471
 
472
          CLEAR_BIT(OPAMP->OTR, OPAMP_OTR_OT_USER);
472
      }
473
        }
473
 
474
       
474
 
475
      }
475
      /* Configure the power supply range */
476
     
476
      MODIFY_REG(tmp_csr, OPAMP_CSR_AOP_RANGE,
477
     
477
                          hopamp->Init.PowerSupplyRange);
478
      /* Configure the power supply range */
478
 
479
      MODIFY_REG(tmp_csr, OPAMP_CSR_AOP_RANGE,
479
      /* Set OPAMP CSR register from temporary variable */
480
                          hopamp->Init.PowerSupplyRange);
480
      /* This allows to apply all changes on one time, in case of update on   */
481
     
481
      /* the fly with OPAMP previously set and running:                       */
482
      /* Set OPAMP CSR register from temporary variable */
482
      /*  - to avoid hazardous transient switches settings (risk of short     */
483
      /* This allows to apply all changes on one time, in case of update on   */
483
      /*    circuit)                                                          */
484
      /* the fly with OPAMP previously set and running:                       */
484
      /*  - to avoid interruption of input signal                             */
485
      /*  - to avoid hazardous transient switches settings (risk of short     */
485
      OPAMP->CSR = tmp_csr;
486
      /*    circuit)                                                          */
486
 
487
      /*  - to avoid interruption of input signal                             */
487
 
488
      OPAMP->CSR = tmp_csr;
488
      /* Update the OPAMP state */
489
 
489
      /* If coming from state reset: Update from state RESET to state READY */
490
               
490
      if (hopamp->State == HAL_OPAMP_STATE_RESET)
491
      /* Update the OPAMP state */
491
      {
492
      /* If coming from state reset: Update from state RESET to state READY */
492
        hopamp->State = HAL_OPAMP_STATE_READY;
493
      if (hopamp->State == HAL_OPAMP_STATE_RESET)
493
      }
494
      {
494
      /* else: OPAMP state remains READY or BUSY state (no update) */
495
        hopamp->State = HAL_OPAMP_STATE_READY;
495
    }
496
      }
496
  }
497
      /* else: OPAMP state remains READY or BUSY state (no update) */
497
 
498
    }
498
  return status;
499
  }
499
}
500
 
500
 
501
  return status;
501
/**
502
}
502
  * @brief  DeInitializes the OPAMP peripheral
503
 
503
  * @note   Deinitialization can be performed if the OPAMP configuration is locked.
504
/**
504
  *         (the OPAMP lock is SW in STM32L1)
505
  * @brief  DeInitializes the OPAMP peripheral
505
  * @param  hopamp OPAMP handle
506
  * @note   Deinitialization can be performed if the OPAMP configuration is locked.
506
  * @retval HAL status
507
  *         (the OPAMP lock is SW in STM32L1)
507
  */
508
  * @param  hopamp OPAMP handle
508
HAL_StatusTypeDef HAL_OPAMP_DeInit(OPAMP_HandleTypeDef* hopamp)
509
  * @retval HAL status
509
{
510
  */
510
  HAL_StatusTypeDef status = HAL_OK;
511
HAL_StatusTypeDef HAL_OPAMP_DeInit(OPAMP_HandleTypeDef* hopamp)
511
 
512
{
512
  /* Check the OPAMP handle allocation */
513
  HAL_StatusTypeDef status = HAL_OK;
513
  /* DeInit not allowed if calibration is ongoing */
514
 
514
  if(hopamp == NULL)
515
  /* Check the OPAMP handle allocation */
515
  {
516
  /* DeInit not allowed if calibration is ongoing */
516
    status = HAL_ERROR;
517
  if(hopamp == NULL)
517
  }
518
  {
518
  else if(hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
519
    status = HAL_ERROR;
519
  {
520
  }
520
    status = HAL_ERROR;
521
  else if(hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
521
  }
522
  {
522
  else
523
    status = HAL_ERROR;
523
  {
524
  }
524
    /* Check the parameter */
525
  else
525
    assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
526
  {
526
 
527
    /* Check the parameter */
527
    /* Disable the selected opamp */
528
    assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
528
    SET_BIT (OPAMP->CSR, OPAMP_CSR_OPAXPD(hopamp));
529
   
529
 
530
    /* Disable the selected opamp */
530
    /* Open all switches on non-inverting input, inverting input and output   */
531
    SET_BIT (OPAMP->CSR, OPAMP_CSR_OPAXPD(hopamp));
531
    /* feedback.                                                              */
532
   
532
    /* Note: OPAMP register CSR is written directly, independently of OPAMP   */
533
    /* Open all switches on non-inverting input, inverting input and output   */
533
    /*       instance, because all OPAMP settings are dispatched in the same  */
534
    /* feedback.                                                              */
534
    /*       register.                                                        */
535
    /* Note: OPAMP register CSR is written directly, independently of OPAMP   */
535
    /*       Settings of bits for each OPAMP instances are managed case by    */
536
    /*       instance, because all OPAMP settings are dispatched in the same  */
536
    /*       case using macro (OPAMP_CSR_S3SELX(), OPAMP_CSR_ANAWSELX(), ...) */
537
    /*       register.                                                        */
537
    CLEAR_BIT(OPAMP->CSR, OPAMP_CSR_ALL_SWITCHES(hopamp));
538
    /*       Settings of bits for each OPAMP instances are managed case by    */
538
 
539
    /*       case using macro (OPAMP_CSR_S3SELX(), OPAMP_CSR_ANAWSELX(), ...) */
539
    /* Note: Registers and bits shared with other OPAMP instances are kept    */
540
    CLEAR_BIT(OPAMP->CSR, OPAMP_CSR_ALL_SWITCHES(hopamp));
540
    /*       unchanged, to not impact other OPAMP while operating on the      */
541
 
541
    /*       selected OPAMP.                                                  */
542
    /* Note: Registers and bits shared with other OPAMP instances are kept    */
542
    /*       Unchanged: bit OPAMP_OTR_OT_USER (parameter "UserTrimming")      */
543
    /*       unchanged, to not impact other OPAMP while operating on the      */
543
    /*                  bit OPAMP_CSR_AOP_RANGE (parameter "PowerSupplyRange")*/
544
    /*       selected OPAMP.                                                  */
544
 
545
    /*       Unchanged: bit OPAMP_OTR_OT_USER (parameter "UserTrimming")      */
545
#if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
546
    /*                  bit OPAMP_CSR_AOP_RANGE (parameter "PowerSupplyRange")*/
546
  if(hopamp->MspDeInitCallback == NULL)
547
 
547
  {
548
#if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
548
    hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
549
  if(hopamp->MspDeInitCallback == NULL)
549
  }
550
  {
550
  /* DeInit the low level hardware */
551
    hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
551
  hopamp->MspDeInitCallback(hopamp);
552
  }
552
#else
553
  /* DeInit the low level hardware */
553
    /* DeInit the low level hardware: GPIO, CLOCK and NVIC */
554
  hopamp->MspDeInitCallback(hopamp);
554
    HAL_OPAMP_MspDeInit(hopamp);
555
#else
555
#endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
556
    /* DeInit the low level hardware: GPIO, CLOCK and NVIC */
556
 
557
    HAL_OPAMP_MspDeInit(hopamp);
557
    /* Update the OPAMP state*/
558
#endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
558
    hopamp->State = HAL_OPAMP_STATE_RESET;
559
 
559
  }
560
    /* Update the OPAMP state*/
560
 
561
    hopamp->State = HAL_OPAMP_STATE_RESET;
561
  /* Process unlocked */
562
  }
562
  __HAL_UNLOCK(hopamp);
563
 
563
 
564
  /* Process unlocked */
564
  return status;
565
  __HAL_UNLOCK(hopamp);
565
}
566
 
566
 
567
  return status;
567
/**
568
}
568
  * @brief  Initialize the OPAMP MSP.
569
 
569
  * @param  hopamp OPAMP handle
570
/**
570
  * @retval None
571
  * @brief  Initialize the OPAMP MSP.
571
  */
572
  * @param  hopamp OPAMP handle
572
__weak void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef* hopamp)
573
  * @retval None
573
{
574
  */
574
  /* Prevent unused argument(s) compilation warning */
575
__weak void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef* hopamp)
575
  UNUSED(hopamp);
576
{
576
 
577
  /* Prevent unused argument(s) compilation warning */
577
  /* NOTE : This function should not be modified, when the callback is needed,
578
  UNUSED(hopamp);
578
            the function "HAL_OPAMP_MspInit()" must be implemented in the user file.
579
 
579
  */
580
  /* NOTE : This function should not be modified, when the callback is needed,
580
}
581
            the function "HAL_OPAMP_MspInit()" must be implemented in the user file.
581
 
582
  */
582
/**
583
}
583
  * @brief  DeInitialize OPAMP MSP.
584
 
584
  * @param  hopamp OPAMP handle
585
/**
585
  * @retval None
586
  * @brief  DeInitialize OPAMP MSP.
586
  */
587
  * @param  hopamp OPAMP handle
587
__weak void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef* hopamp)
588
  * @retval None
588
{
589
  */
589
  /* Prevent unused argument(s) compilation warning */
590
__weak void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef* hopamp)
590
  UNUSED(hopamp);
591
{
591
 
592
  /* Prevent unused argument(s) compilation warning */
592
  /* NOTE : This function should not be modified, when the callback is needed,
593
  UNUSED(hopamp);
593
            the function "HAL_OPAMP_MspDeInit()" must be implemented in the user file.
594
 
594
  */
595
  /* NOTE : This function should not be modified, when the callback is needed,
595
}
596
            the function "HAL_OPAMP_MspDeInit()" must be implemented in the user file.
596
 
597
  */
597
/**
598
}
598
  * @}
599
 
599
  */
600
/**
600
 
601
  * @}
601
 
602
  */
602
/** @defgroup OPAMP_Exported_Functions_Group2 IO operation functions
603
 
603
  * @brief   IO operation functions
604
 
604
  *
605
/** @defgroup OPAMP_Exported_Functions_Group2 IO operation functions
605
@verbatim
606
  * @brief   IO operation functions
606
 ===============================================================================
607
  *
607
                        ##### IO operation functions #####
608
@verbatim  
608
 ===============================================================================
609
 ===============================================================================
609
    [..]
610
                        ##### IO operation functions #####
610
    This subsection provides a set of functions allowing to manage the OPAMP
611
 ===============================================================================
611
    start, stop and calibration actions.
612
    [..]
612
 
613
    This subsection provides a set of functions allowing to manage the OPAMP
613
@endverbatim
614
    start, stop and calibration actions.
614
  * @{
615
 
615
  */
616
@endverbatim
616
 
617
  * @{
617
/**
618
  */
618
  * @brief  Start the OPAMP.
619
 
619
  * @param  hopamp OPAMP handle
620
/**
620
  * @retval HAL status
621
  * @brief  Start the OPAMP.
621
  */
622
  * @param  hopamp OPAMP handle
622
 
623
  * @retval HAL status
623
HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef* hopamp)
624
  */
624
{
625
 
625
  HAL_StatusTypeDef status = HAL_OK;
626
HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef* hopamp)
626
 
627
{
627
  /* Check the OPAMP handle allocation */
628
  HAL_StatusTypeDef status = HAL_OK;
628
  /* Check if OPAMP locked */
629
 
629
  if(hopamp == NULL)
630
  /* Check the OPAMP handle allocation */
630
  {
631
  /* Check if OPAMP locked */
631
    status = HAL_ERROR;
632
  if(hopamp == NULL)
632
  }
633
  {
633
  else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
634
    status = HAL_ERROR;
634
  {
635
  }
635
    status = HAL_ERROR;
636
  else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
636
  }
637
  {
637
  else
638
    status = HAL_ERROR;
638
  {
639
  }
639
    /* Check the parameter */
640
  else
640
    assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
641
  {
641
 
642
    /* Check the parameter */
642
    if(hopamp->State == HAL_OPAMP_STATE_READY)
643
    assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
643
    {
644
   
644
      /* Enable the selected opamp */
645
    if(hopamp->State == HAL_OPAMP_STATE_READY)
645
      CLEAR_BIT (OPAMP->CSR, OPAMP_CSR_OPAXPD(hopamp));
646
    {
646
 
647
      /* Enable the selected opamp */
647
      /* Update the OPAMP state */
648
      CLEAR_BIT (OPAMP->CSR, OPAMP_CSR_OPAXPD(hopamp));
648
      /* From HAL_OPAMP_STATE_READY to HAL_OPAMP_STATE_BUSY */
649
     
649
      hopamp->State = HAL_OPAMP_STATE_BUSY;
650
      /* Update the OPAMP state */
650
    }
651
      /* From HAL_OPAMP_STATE_READY to HAL_OPAMP_STATE_BUSY */
651
    else
652
      hopamp->State = HAL_OPAMP_STATE_BUSY;  
652
    {
653
    }
653
      status = HAL_ERROR;
654
    else
654
    }
655
    {
655
 
656
      status = HAL_ERROR;
656
   }
657
    }
657
  return status;
658
   
658
}
659
   }
659
 
660
  return status;
660
/**
661
}
661
  * @brief  Stop the OPAMP.
662
 
662
  * @param  hopamp OPAMP handle
663
/**
663
  * @retval HAL status
664
  * @brief  Stop the OPAMP.
664
  */
665
  * @param  hopamp OPAMP handle
665
HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef* hopamp)
666
  * @retval HAL status
666
{
667
  */
667
  HAL_StatusTypeDef status = HAL_OK;
668
HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef* hopamp)
668
 
669
{
669
  /* Check the OPAMP handle allocation */
670
  HAL_StatusTypeDef status = HAL_OK;
670
  /* Check if OPAMP locked */
671
   
671
  /* Check if OPAMP calibration ongoing */
672
  /* Check the OPAMP handle allocation */
672
  if(hopamp == NULL)
673
  /* Check if OPAMP locked */
673
  {
674
  /* Check if OPAMP calibration ongoing */
674
    status = HAL_ERROR;
675
  if(hopamp == NULL)
675
  }
676
  {
676
  else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
677
    status = HAL_ERROR;
677
  {
678
  }
678
    status = HAL_ERROR;
679
  else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
679
  }
680
  {
680
  else if(hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
681
    status = HAL_ERROR;
681
  {
682
  }
682
    status = HAL_ERROR;
683
  else if(hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
683
  }
684
  {
684
  else
685
    status = HAL_ERROR;
685
  {
686
  }
686
    /* Check the parameter */
687
  else
687
    assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
688
  {
688
 
689
    /* Check the parameter */
689
    if(hopamp->State == HAL_OPAMP_STATE_BUSY)
690
    assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
690
    {
691
 
691
      /* Disable the selected opamp */
692
    if(hopamp->State == HAL_OPAMP_STATE_BUSY)
692
      SET_BIT (OPAMP->CSR, OPAMP_CSR_OPAXPD(hopamp));
693
    {
693
 
694
      /* Disable the selected opamp */
694
      /* Update the OPAMP state*/
695
      SET_BIT (OPAMP->CSR, OPAMP_CSR_OPAXPD(hopamp));
695
      /* From  HAL_OPAMP_STATE_BUSY to HAL_OPAMP_STATE_READY*/
696
     
696
      hopamp->State = HAL_OPAMP_STATE_READY;
697
      /* Update the OPAMP state*/    
697
    }
698
      /* From  HAL_OPAMP_STATE_BUSY to HAL_OPAMP_STATE_READY*/
698
    else
699
      hopamp->State = HAL_OPAMP_STATE_READY;
699
    {
700
    }
700
      status = HAL_ERROR;
701
    else
701
    }
702
    {
702
  }
703
      status = HAL_ERROR;
703
  return status;
704
    }
704
}
705
  }
705
 
706
  return status;
706
/**
707
}
707
  * @brief  Run the self calibration of one OPAMP.
708
 
708
  * @note   Trimming values (PMOS & NMOS) are updated and user trimming is
709
/**
709
  *         enabled if calibration is successful.
710
  * @brief  Run the self calibration of one OPAMP.
710
  * @note   Calibration is performed in the mode specified in OPAMP init
711
  * @note   Trimming values (PMOS & NMOS) are updated and user trimming is
711
  *         structure (mode normal or low-power). To perform calibration for
712
  *         enabled if calibration is succesful.
712
  *         both modes, repeat this function twice after OPAMP init structure
713
  * @note   Calibration is performed in the mode specified in OPAMP init
713
  *         accordingly updated.
714
  *         structure (mode normal or low-power). To perform calibration for
714
  * @note   Calibration runs about 10 ms.
715
  *         both modes, repeat this function twice after OPAMP init structure
715
  * @param  hopamp handle
716
  *         accordingly updated.
716
  * @retval Updated offset trimming values (PMOS & NMOS), user trimming is enabled
717
  * @note   Calibration runs about 10 ms.
717
  * @retval HAL status
718
  * @param  hopamp handle
718
  */
719
  * @retval Updated offset trimming values (PMOS & NMOS), user trimming is enabled
719
HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef* hopamp)
720
  * @retval HAL status
720
{
721
  */
721
  HAL_StatusTypeDef status = HAL_OK;
722
HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef* hopamp)
722
 
723
{
723
  uint32_t* opamp_trimmingvalue;
724
  HAL_StatusTypeDef status = HAL_OK;
724
  uint32_t opamp_trimmingvaluen = 0;
725
 
725
  uint32_t opamp_trimmingvaluep = 0;
726
  uint32_t* opamp_trimmingvalue;
726
 
727
  uint32_t opamp_trimmingvaluen = 0;
727
  uint32_t trimming_diff_pair;               /* Selection of differential transistors pair high or low */
728
  uint32_t opamp_trimmingvaluep = 0;
728
 
729
 
729
  __IO uint32_t* tmp_opamp_reg_trimming;     /* Selection of register of trimming depending on power mode: OTR or LPOTR */
730
  uint32_t trimming_diff_pair;               /* Selection of differential transistors pair high or low */
730
  uint32_t tmp_opamp_otr_otuser;             /* Selection of bit OPAMP_OTR_OT_USER depending on trimming register pointed: OTR or LPOTR */
731
 
731
 
732
  __IO uint32_t* tmp_opamp_reg_trimming;     /* Selection of register of trimming depending on power mode: OTR or LPOTR */
732
  uint32_t tmp_Opaxcalout_DefaultSate;       /* Bit OPAMP_CSR_OPAXCALOUT default state when trimming value is 00000b. Used to detect the bit toggling */
733
  uint32_t tmp_opamp_otr_otuser;             /* Selection of bit OPAMP_OTR_OT_USER depending on trimming register pointed: OTR or LPOTR */
733
 
734
 
734
  uint32_t tmp_OpaxSwitchesContextBackup;
735
  uint32_t tmp_Opaxcalout_DefaultSate;       /* Bit OPAMP_CSR_OPAXCALOUT default state when trimming value is 00000b. Used to detect the bit toggling */
735
 
736
 
736
  uint8_t trimming_diff_pair_iteration_count;          /* For calibration loop algorithm: to repeat the calibration loop for both differential transistors pair high and low */
737
  uint32_t tmp_OpaxSwitchesContextBackup;
737
  uint8_t delta;                                       /* For calibration loop algorithm: Variable for dichotomy steps value */
738
 
738
  uint8_t final_step_check = 0x0U;                        /* For calibration loop algorithm: Flag for additional check of last trimming step */
739
  uint8_t trimming_diff_pair_iteration_count;          /* For calibration loop algorithm: to repeat the calibration loop for both differential transistors pair high and low */
739
 
740
  uint8_t delta;                                       /* For calibration loop algorithm: Variable for dichotomy steps value */
740
  /* Check the OPAMP handle allocation */
741
  uint8_t final_step_check = 0x0U;                        /* For calibration loop algorithm: Flag for additional check of last trimming step */
741
  /* Check if OPAMP locked */
742
 
742
  if(hopamp == NULL)
743
  /* Check the OPAMP handle allocation */
743
  {
744
  /* Check if OPAMP locked */
744
    status = HAL_ERROR;
745
  if(hopamp == NULL)
745
  }
746
  {
746
  else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
747
    status = HAL_ERROR;
747
  {
748
  }
748
    status = HAL_ERROR;
749
  else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
749
  }
750
  {
750
  else
751
    status = HAL_ERROR;
751
  {
752
  }
752
 
753
  else
753
    /* Check if OPAMP in calibration mode and calibration not yet enable */
754
  {
754
    if(hopamp->State == HAL_OPAMP_STATE_READY)
755
 
755
    {
756
    /* Check if OPAMP in calibration mode and calibration not yet enable */
756
      /* Check the parameter */
757
    if(hopamp->State == HAL_OPAMP_STATE_READY)
757
      assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
758
    {
758
      assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
759
      /* Check the parameter */
759
 
760
      assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
760
      /* Update OPAMP state */
761
      assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
761
      hopamp->State = HAL_OPAMP_STATE_CALIBBUSY;
762
     
762
 
763
      /* Update OPAMP state */
763
      /* Backup of switches configuration to restore it at the end of the     */
764
      hopamp->State = HAL_OPAMP_STATE_CALIBBUSY;
764
      /* calibration.                                                         */
765
     
765
      tmp_OpaxSwitchesContextBackup = READ_BIT(OPAMP->CSR, OPAMP_CSR_ALL_SWITCHES(hopamp));
766
      /* Backup of switches configuration to restore it at the end of the     */
766
 
767
      /* calibration.                                                         */
767
      /* Open all switches on non-inverting input, inverting input and output */
768
      tmp_OpaxSwitchesContextBackup = READ_BIT(OPAMP->CSR, OPAMP_CSR_ALL_SWITCHES(hopamp));
768
      /* feedback.                                                            */
769
 
769
      CLEAR_BIT(OPAMP->CSR, OPAMP_CSR_ALL_SWITCHES(hopamp));
770
      /* Open all switches on non-inverting input, inverting input and output */
770
 
771
      /* feedback.                                                            */
771
      /* Set calibration mode to user programmed trimming values */
772
      CLEAR_BIT(OPAMP->CSR, OPAMP_CSR_ALL_SWITCHES(hopamp));
772
      SET_BIT(OPAMP->OTR, OPAMP_OTR_OT_USER);
773
 
773
 
774
      /* Set calibration mode to user programmed trimming values */
774
 
775
      SET_BIT(OPAMP->OTR, OPAMP_OTR_OT_USER);
775
      /* Select trimming settings depending on power mode */
776
 
776
      if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
777
     
777
      {
778
      /* Select trimming settings depending on power mode */
778
        tmp_opamp_otr_otuser = OPAMP_OTR_OT_USER;
779
      if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
779
        tmp_opamp_reg_trimming = &OPAMP->OTR;
780
      {
780
      }
781
        tmp_opamp_otr_otuser = OPAMP_OTR_OT_USER;
781
      else
782
        tmp_opamp_reg_trimming = &OPAMP->OTR;
782
      {
783
      }
783
        tmp_opamp_otr_otuser = 0x00000000U;
784
      else
784
        tmp_opamp_reg_trimming = &OPAMP->LPOTR;
785
      {
785
      }
786
        tmp_opamp_otr_otuser = 0x00000000U;
786
 
787
        tmp_opamp_reg_trimming = &OPAMP->LPOTR;
787
 
788
      }
788
      /* Enable the selected opamp */
789
 
789
      CLEAR_BIT (OPAMP->CSR, OPAMP_CSR_OPAXPD(hopamp));
790
     
790
 
791
      /* Enable the selected opamp */
791
      /* Perform trimming for both differential transistors pair high and low */
792
      CLEAR_BIT (OPAMP->CSR, OPAMP_CSR_OPAXPD(hopamp));
792
      for (trimming_diff_pair_iteration_count = 0U; trimming_diff_pair_iteration_count <=1U; trimming_diff_pair_iteration_count++)
793
 
793
      {
794
      /* Perform trimming for both differential transistors pair high and low */
794
        if (trimming_diff_pair_iteration_count == 0U)
795
      for (trimming_diff_pair_iteration_count = 0U; trimming_diff_pair_iteration_count <=1U; trimming_diff_pair_iteration_count++)
795
        {
796
      {
796
          /* Calibration of transistors differential pair high (NMOS) */
797
        if (trimming_diff_pair_iteration_count == 0U)
797
          trimming_diff_pair = OPAMP_FACTORYTRIMMING_N;
798
        {
798
          opamp_trimmingvalue = &opamp_trimmingvaluen;
799
          /* Calibration of transistors differential pair high (NMOS) */
799
 
800
          trimming_diff_pair = OPAMP_FACTORYTRIMMING_N;
800
          /* Set bit OPAMP_CSR_OPAXCALOUT default state when trimming value   */
801
          opamp_trimmingvalue = &opamp_trimmingvaluen;
801
          /* is 00000b. Used to detect the bit toggling during trimming.      */
802
         
802
          tmp_Opaxcalout_DefaultSate = 0U;
803
          /* Set bit OPAMP_CSR_OPAXCALOUT default state when trimming value   */
803
 
804
          /* is 00000b. Used to detect the bit toggling during trimming.      */
804
          /* Enable calibration for N differential pair */
805
          tmp_Opaxcalout_DefaultSate = 0U;
805
          MODIFY_REG(OPAMP->CSR, OPAMP_CSR_OPAXCAL_L(hopamp),
806
 
806
                                 OPAMP_CSR_OPAXCAL_H(hopamp) );
807
          /* Enable calibration for N differential pair */
807
        }
808
          MODIFY_REG(OPAMP->CSR, OPAMP_CSR_OPAXCAL_L(hopamp),
808
        else /* (trimming_diff_pair_iteration_count == 1) */
809
                                 OPAMP_CSR_OPAXCAL_H(hopamp) );
809
        {
810
        }
810
          /* Calibration of transistors differential pair low (PMOS) */
811
        else /* (trimming_diff_pair_iteration_count == 1) */
811
          trimming_diff_pair = OPAMP_FACTORYTRIMMING_P;
812
        {
812
          opamp_trimmingvalue = &opamp_trimmingvaluep;
813
          /* Calibration of transistors differential pair low (PMOS) */
813
 
814
          trimming_diff_pair = OPAMP_FACTORYTRIMMING_P;
814
          /* Set bit OPAMP_CSR_OPAXCALOUT default state when trimming value   */
815
          opamp_trimmingvalue = &opamp_trimmingvaluep;
815
          /* is 00000b. Used to detect the bit toggling during trimming.      */
816
         
816
          tmp_Opaxcalout_DefaultSate = OPAMP_CSR_OPAXCALOUT(hopamp);
817
          /* Set bit OPAMP_CSR_OPAXCALOUT default state when trimming value   */
817
 
818
          /* is 00000b. Used to detect the bit toggling during trimming.      */
818
          /* Enable calibration for P differential pair */
819
          tmp_Opaxcalout_DefaultSate = OPAMP_CSR_OPAXCALOUT(hopamp);
819
          MODIFY_REG(OPAMP->CSR, OPAMP_CSR_OPAXCAL_H(hopamp),
820
         
820
                                 OPAMP_CSR_OPAXCAL_L(hopamp) );
821
          /* Enable calibration for P differential pair */
821
        }
822
          MODIFY_REG(OPAMP->CSR, OPAMP_CSR_OPAXCAL_H(hopamp),
822
 
823
                                 OPAMP_CSR_OPAXCAL_L(hopamp) );
823
 
824
        }
824
        /* Perform calibration parameter search by dichotomy sweep */
825
       
825
        /*  - Delta initial value 16: for 5 dichotomy steps: 16 for the       */
826
     
826
        /*    initial range, then successive delta sweeps (8, 4, 2, 1).       */
827
        /* Perform calibration parameter search by dichotomy sweep */
827
        /*    can extend the search range to +/- 15 units.                    */
828
        /*  - Delta initial value 16: for 5 dichotomy steps: 16 for the       */
828
        /*  - Trimming initial value 15: search range will go from 0 to 30    */
829
        /*    initial range, then successive delta sweeps (8, 4, 2, 1).       */
829
        /*    (Trimming value 31 is forbidden).                               */
830
        /*    can extend the search range to +/- 15 units.                    */
830
        /* Note: After dichotomy sweep, the trimming result is determined.    */
831
        /*  - Trimming initial value 15: search range will go from 0 to 30    */
831
        /*       However, the final trimming step is deduced from previous    */
832
        /*    (Trimming value 31 is forbidden).                               */
832
        /*       trimming steps tested but is not effectively tested.         */
833
        /* Note: After dichotomy sweep, the trimming result is determined.    */
833
        /*       An additional test step (using variable "final_step_check")  */
834
        /*       However, the final trimming step is deduced from previous    */
834
        /*       allow to Test the final trimming step.                       */
835
        /*       trimming steps tested but is not effectively tested.         */
835
        *opamp_trimmingvalue = 15U;
836
        /*       An additional test step (using variable "final_step_check")  */
836
        delta = 16U;
837
        /*       allow to Test the final trimming step.                       */
837
 
838
        *opamp_trimmingvalue = 15U;
838
        while ((delta != 0U) || (final_step_check == 1U))
839
        delta = 16U;
839
        {
840
 
840
          /* Set candidate trimming */
841
        while ((delta != 0U) || (final_step_check == 1U))
841
          MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OFFSET_TRIM_SET(hopamp, trimming_diff_pair, OPAMP_TRIM_VALUE_MASK) ,
842
        {
842
                                              OPAMP_OFFSET_TRIM_SET(hopamp, trimming_diff_pair, *opamp_trimmingvalue) | tmp_opamp_otr_otuser);
843
          /* Set candidate trimming */
843
 
844
          MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OFFSET_TRIM_SET(hopamp, trimming_diff_pair, OPAMP_TRIM_VALUE_MASK) ,
844
          /* Offset trimming time: during calibration, minimum time needed    */
845
                                              OPAMP_OFFSET_TRIM_SET(hopamp, trimming_diff_pair, *opamp_trimmingvalue) | tmp_opamp_otr_otuser);
845
          /* between two steps to have 1 mV accuracy.                         */
846
         
846
          HAL_Delay(OPAMP_TRIMMING_DELAY);
847
          /* Offset trimming time: during calibration, minimum time needed    */
847
 
848
          /* between two steps to have 1 mV accuracy.                         */
848
          /* Set flag for additional check of last trimming step equal to     */
849
          HAL_Delay(OPAMP_TRIMMING_DELAY);
849
          /* dichotomy step before its division by 2 (equivalent to previous  */
850
 
850
          /* value of dichotomy step).                                        */
851
          /* Set flag for additional check of last trimming step equal to     */
851
          final_step_check = delta;
852
          /* dichotomy step before its division by 2 (equivalent to previous  */
852
 
853
          /* value of dichotomy step).                                        */
853
          /* Divide range by 2 to continue dichotomy sweep */
854
          final_step_check = delta;
854
          delta >>= 1;
855
         
855
 
856
          /* Divide range by 2 to continue dichotomy sweep */
856
          /* Set trimming values for next iteration in function of trimming   */
857
          delta >>= 1;
857
          /* result toggle (versus initial state).                            */
858
           
858
          /* Note: on the last trimming loop, delta is equal to 0 and         */
859
          /* Set trimming values for next iteration in function of trimming   */
859
          /*       therefore has no effect.                                   */
860
          /* result toggle (versus initial state).                            */
860
          if (READ_BIT(OPAMP->CSR, OPAMP_CSR_OPAXCALOUT(hopamp)) != tmp_Opaxcalout_DefaultSate)
861
          /* Note: on the last trimming loop, delta is equal to 0 and         */
861
          {
862
          /*       therefore has no effect.                                   */
862
            /* If calibration output is has toggled, try lower trimming */
863
          if (READ_BIT(OPAMP->CSR, OPAMP_CSR_OPAXCALOUT(hopamp)) != tmp_Opaxcalout_DefaultSate)
863
            *opamp_trimmingvalue -= delta;
864
          {
864
          }
865
            /* If calibration output is has toggled, try lower trimming */
865
          else
866
            *opamp_trimmingvalue -= delta;
866
          {
867
          }
867
            /* If calibration output is has not toggled, try higher trimming */
868
          else
868
            *opamp_trimmingvalue += delta;
869
          {
869
          }
870
            /* If calibration output is has not toggled, try higher trimming */
870
 
871
            *opamp_trimmingvalue += delta;
871
        }
872
          }
872
 
873
 
873
        /* Check trimming result of the selected step and perform final fine  */
874
        }
874
        /* trimming.                                                          */
875
       
875
        /*  - If calibration output is has toggled: the current step is       */
876
        /* Check trimming result of the selected step and perform final fine  */
876
        /*    already optimized.                                              */
877
        /* trimming.                                                          */
877
        /*  - If calibration output is has not toggled: the current step can  */
878
        /*  - If calibration output is has toggled: the current step is       */
878
        /*    be optimized by incrementing it of one step.                    */
879
        /*    already optimized.                                              */
879
        if (READ_BIT(OPAMP->CSR, OPAMP_CSR_OPAXCALOUT(hopamp)) == tmp_Opaxcalout_DefaultSate)
880
        /*  - If calibration output is has not toggled: the current step can  */
880
        {
881
        /*    be optimized by incrementing it of one step.                    */
881
          *opamp_trimmingvalue += 1U;
882
        if (READ_BIT(OPAMP->CSR, OPAMP_CSR_OPAXCALOUT(hopamp)) == tmp_Opaxcalout_DefaultSate)
882
 
883
        {
883
          /* Set final fine trimming */
884
          *opamp_trimmingvalue += 1U;
884
          MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OFFSET_TRIM_SET(hopamp, trimming_diff_pair, OPAMP_TRIM_VALUE_MASK) ,
885
         
885
                                              OPAMP_OFFSET_TRIM_SET(hopamp, trimming_diff_pair, *opamp_trimmingvalue) | tmp_opamp_otr_otuser);
886
          /* Set final fine trimming */
886
        }
887
          MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OFFSET_TRIM_SET(hopamp, trimming_diff_pair, OPAMP_TRIM_VALUE_MASK) ,
887
 
888
                                              OPAMP_OFFSET_TRIM_SET(hopamp, trimming_diff_pair, *opamp_trimmingvalue) | tmp_opamp_otr_otuser);
888
      }
889
        }
889
 
890
       
890
 
891
      }
891
      /* Disable calibration for P and N differential pairs */
892
 
892
      /* Disable the selected opamp */
893
     
893
      CLEAR_BIT (OPAMP->CSR, (OPAMP_CSR_OPAXCAL_H(hopamp) |
894
      /* Disable calibration for P and N differential pairs */
894
                              OPAMP_CSR_OPAXCAL_L(hopamp) |
895
      /* Disable the selected opamp */
895
                              OPAMP_CSR_OPAXPD(hopamp))    );
896
      CLEAR_BIT (OPAMP->CSR, (OPAMP_CSR_OPAXCAL_H(hopamp) |
896
 
897
                              OPAMP_CSR_OPAXCAL_L(hopamp) |
897
      /* Backup of switches configuration to restore it at the end of the     */
898
                              OPAMP_CSR_OPAXPD(hopamp))    );
898
      /* calibration.                                                         */
899
 
899
      SET_BIT(OPAMP->CSR, tmp_OpaxSwitchesContextBackup);
900
      /* Backup of switches configuration to restore it at the end of the     */
900
 
901
      /* calibration.                                                         */
901
      /* Self calibration is successful */
902
      SET_BIT(OPAMP->CSR, tmp_OpaxSwitchesContextBackup);
902
      /* Store calibration (user trimming) results in init structure. */
903
     
903
 
904
      /* Self calibration is successful */
904
      /* Set user trimming mode */
905
      /* Store calibration (user trimming) results in init structure. */
905
      hopamp->Init.UserTrimming = OPAMP_TRIMMING_USER;
906
     
906
 
907
      /* Set user trimming mode */  
907
      /* Check on unsupported value */
908
      hopamp->Init.UserTrimming = OPAMP_TRIMMING_USER;
908
      if(opamp_trimmingvaluep == 0x1FU)  /* 0x1F is not functional */
909
     
909
      {
910
      /* Check on unsupported value */
910
        opamp_trimmingvaluep = 30U;
911
      if(opamp_trimmingvaluep == 0x1FU)  /* 0x1F is not functional */
911
      }
912
      {
912
 
913
        opamp_trimmingvaluep = 30U;
913
      if(opamp_trimmingvaluen == 0x1FU)  /* 0x1F is not functional */
914
      }
914
      {
915
       
915
        opamp_trimmingvaluen = 30U;
916
      if(opamp_trimmingvaluen == 0x1FU)  /* 0x1F is not functional */
916
      }
917
      {
917
 
918
        opamp_trimmingvaluen = 30U;
918
      /* Affect calibration parameters depending on mode normal/low power */
919
      }
919
      if (hopamp->Init.PowerMode != OPAMP_POWERMODE_LOWPOWER)
920
 
920
      {
921
      /* Affect calibration parameters depending on mode normal/low power */
921
        /* Write calibration result N */
922
      if (hopamp->Init.PowerMode != OPAMP_POWERMODE_LOWPOWER)
922
        hopamp->Init.TrimmingValueN = opamp_trimmingvaluen;
923
      {
923
        /* Write calibration result P */
924
        /* Write calibration result N */
924
        hopamp->Init.TrimmingValueP = opamp_trimmingvaluep;
925
        hopamp->Init.TrimmingValueN = opamp_trimmingvaluen;
925
      }
926
        /* Write calibration result P */
926
      else
927
        hopamp->Init.TrimmingValueP = opamp_trimmingvaluep;
927
      {
928
      }
928
        /* Write calibration result N */
929
      else
929
        hopamp->Init.TrimmingValueNLowPower = opamp_trimmingvaluen;
930
      {
930
        /* Write calibration result P */
931
        /* Write calibration result N */
931
        hopamp->Init.TrimmingValuePLowPower = opamp_trimmingvaluep;
932
        hopamp->Init.TrimmingValueNLowPower = opamp_trimmingvaluen;
932
      }
933
        /* Write calibration result P */
933
 
934
        hopamp->Init.TrimmingValuePLowPower = opamp_trimmingvaluep;
934
      /* Update OPAMP state */
935
      }
935
      hopamp->State = HAL_OPAMP_STATE_READY;
936
     
936
 
937
      /* Update OPAMP state */
937
    }
938
      hopamp->State = HAL_OPAMP_STATE_READY;
938
 
939
 
939
    else
940
    }
940
    {
941
   
941
      /* OPAMP can not be calibrated from this mode */
942
    else
942
      status = HAL_ERROR;
943
    {
943
    }
944
      /* OPAMP can not be calibrated from this mode */
944
  }
945
      status = HAL_ERROR;
945
 
946
    }
946
  return status;
947
  }
947
 
948
 
948
}
949
  return status;
949
 
950
 
950
/**
951
}
951
  * @}
952
 
952
  */
953
/**
953
 
954
  * @}
954
/**
955
  */
955
  * @}
956
 
956
  */
957
/**
957
 
958
  * @}
958
/** @defgroup OPAMP_Exported_Functions_Group3 Peripheral Control functions
959
  */
959
 *  @brief   Peripheral Control functions
960
     
960
 *
961
/** @defgroup OPAMP_Exported_Functions_Group3 Peripheral Control functions
961
@verbatim
962
 *  @brief   Peripheral Control functions
962
 ===============================================================================
963
 *
963
                      ##### Peripheral Control functions #####
964
@verbatim  
964
 ===============================================================================
965
 ===============================================================================
965
    [..]
966
                      ##### Peripheral Control functions #####
966
    This subsection provides a set of functions allowing to control the OPAMP data
967
 ===============================================================================  
967
    transfers.
968
    [..]
968
 
969
    This subsection provides a set of functions allowing to control the OPAMP data
969
 
970
    transfers.
970
 
971
 
971
@endverbatim
972
 
972
  * @{
973
 
973
  */
974
@endverbatim
974
 
975
  * @{
975
/**
976
  */
976
  * @brief  Lock the selected opamp configuration.
977
 
977
  *         Caution: On STM32L1, HAL OPAMP lock is software lock only
978
/**
978
  *         (not hardware lock as available on some other STM32 devices)
979
  * @brief  Lock the selected opamp configuration.
979
  * @param  hopamp OPAMP handle
980
  *         Caution: On STM32L1, HAL OPAMP lock is software lock only
980
  * @retval HAL status
981
  *         (not hardware lock as available on some other STM32 devices)
981
  */
982
  * @param  hopamp OPAMP handle
982
HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef* hopamp)
983
  * @retval HAL status
983
{
984
  */
984
  HAL_StatusTypeDef status = HAL_OK;
985
HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef* hopamp)
985
 
986
{
986
  /* Check the OPAMP handle allocation */
987
  HAL_StatusTypeDef status = HAL_OK;
987
  /* Check if OPAMP locked */
988
 
988
  /* OPAMP can be locked when enabled and running in normal mode */
989
  /* Check the OPAMP handle allocation */
989
  /*   It is meaningless otherwise */
990
  /* Check if OPAMP locked */
990
  if(hopamp == NULL)
991
  /* OPAMP can be locked when enabled and running in normal mode */
991
  {
992
  /*   It is meaningless otherwise */
992
    status = HAL_ERROR;
993
  if(hopamp == NULL)
993
  }
994
  {
994
  else if(hopamp->State == HAL_OPAMP_STATE_BUSY)
995
    status = HAL_ERROR;
995
  {
996
  }
996
    /* Check the parameter */
997
  else if(hopamp->State == HAL_OPAMP_STATE_BUSY)
997
    assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
998
  {
998
 
999
    /* Check the parameter */
999
   /* OPAMP state changed to locked */
1000
    assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
1000
    hopamp->State = HAL_OPAMP_STATE_BUSYLOCKED;
1001
 
1001
  }
1002
   /* OPAMP state changed to locked */
1002
  else
1003
    hopamp->State = HAL_OPAMP_STATE_BUSYLOCKED;
1003
  {
1004
  }
1004
    status = HAL_ERROR;
1005
  else
1005
  }
1006
  {
1006
  return status;
1007
    status = HAL_ERROR;
1007
}
1008
  }
1008
 
1009
  return status;
1009
/**
1010
}
1010
  * @brief  Return the OPAMP factory trimming value
1011
 
1011
  *         Caution: On STM32L1 OPAMP, user can retrieve factory trimming if
1012
/**
1012
  *                  OPAMP has never been set to user trimming before.
1013
  * @brief  Return the OPAMP factory trimming value
1013
  *                  Therefore, this function must be called when OPAMP init
1014
  *         Caution: On STM32L1 OPAMP, user can retrieve factory trimming if
1014
  *                  parameter "UserTrimming" is set to trimming factory,
1015
  *                  OPAMP has never been set to user trimming before.
1015
  *                  and before OPAMP  calibration (function
1016
  *                  Therefore, this fonction must be called when OPAMP init  
1016
  *                  "HAL_OPAMP_SelfCalibrate()").
1017
  *                  parameter "UserTrimming" is set to trimming factory,
1017
  *                  Otherwise, factory trimming value cannot be retrieved and
1018
  *                  and before OPAMP  calibration (function
1018
  *                  error status is returned.
1019
  *                  "HAL_OPAMP_SelfCalibrate()").
1019
  * @param  hopamp  OPAMP handle
1020
  *                  Otherwise, factory triming value cannot be retrieved and
1020
  * @param  trimmingoffset  Trimming offset (P or N)
1021
  *                  error status is returned.
1021
  *         This parameter must be a value of @ref OPAMP_FactoryTrimming
1022
  * @param  hopamp  OPAMP handle
1022
  * @note   Calibration parameter retrieved is corresponding to the mode
1023
  * @param  trimmingoffset  Trimming offset (P or N)
1023
  *         specified in OPAMP init structure (mode normal or low-power).
1024
  *         This parameter must be a value of @ref OPAMP_FactoryTrimming
1024
  *         To retrieve calibration parameters for both modes, repeat this
1025
  * @note   Calibration parameter retrieved is corresponding to the mode
1025
  *         function after OPAMP init structure accordingly updated.
1026
  *         specified in OPAMP init structure (mode normal or low-power).
1026
  * @retval Trimming value (P or N) range: 0->31
1027
  *         To retrieve calibration parameters for both modes, repeat this
1027
  *         or OPAMP_FACTORYTRIMMING_DUMMY if trimming value is not available
1028
  *         function after OPAMP init structure accordingly updated.
1028
  *
1029
  * @retval Trimming value (P or N) range: 0->31
1029
  */
1030
  *         or OPAMP_FACTORYTRIMMING_DUMMY if trimming value is not available
1030
HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset)
1031
  *
1031
{
1032
  */
1032
  HAL_OPAMP_TrimmingValueTypeDef trimmingvalue;
1033
HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset)
1033
  __IO uint32_t* tmp_opamp_reg_trimming;  /* Selection of register of trimming depending on power mode: OTR or LPOTR */
1034
{
1034
 
1035
  HAL_OPAMP_TrimmingValueTypeDef trimmingvalue;
1035
  /* Check the OPAMP handle allocation */
1036
  __IO uint32_t* tmp_opamp_reg_trimming;  /* Selection of register of trimming depending on power mode: OTR or LPOTR */
1036
  /* Value can be retrieved in HAL_OPAMP_STATE_READY state */
1037
 
1037
  if(hopamp == NULL)
1038
  /* Check the OPAMP handle allocation */
1038
  {
1039
  /* Value can be retrieved in HAL_OPAMP_STATE_READY state */
1039
    return OPAMP_FACTORYTRIMMING_DUMMY;
1040
  if(hopamp == NULL)
1040
  }
1041
  {
1041
 
1042
    return OPAMP_FACTORYTRIMMING_DUMMY;
1042
  /* Check the OPAMP handle allocation */
1043
  }
1043
  /* Value can be retrieved in HAL_OPAMP_STATE_READY state */
1044
 
1044
  if(hopamp->State == HAL_OPAMP_STATE_READY)
1045
  /* Check the OPAMP handle allocation */
1045
  {
1046
  /* Value can be retrieved in HAL_OPAMP_STATE_READY state */
1046
    /* Check the parameter */
1047
  if(hopamp->State == HAL_OPAMP_STATE_READY)
1047
    assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
1048
  {
1048
    assert_param(IS_OPAMP_FACTORYTRIMMING(trimmingoffset));
1049
    /* Check the parameter */
1049
    assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
1050
    assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
1050
 
1051
    assert_param(IS_OPAMP_FACTORYTRIMMING(trimmingoffset));
1051
    /* Check the trimming mode */
1052
    assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
1052
    if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
1053
   
1053
    {
1054
    /* Check the trimming mode */
1054
      /* This function must called when OPAMP init parameter "UserTrimming"   */
1055
    if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
1055
      /* is set to trimming factory, and before OPAMP calibration (function   */
1056
    {
1056
      /* "HAL_OPAMP_SelfCalibrate()").                                        */
1057
      /* This fonction must called when OPAMP init parameter "UserTrimming"   */
1057
      /* Otherwise, factory trimming value cannot be retrieved and error       */
1058
      /* is set to trimming factory, and before OPAMP calibration (function   */
1058
      /* status is returned.                                                  */
1059
      /* "HAL_OPAMP_SelfCalibrate()").                                        */
1059
      trimmingvalue = OPAMP_FACTORYTRIMMING_DUMMY;
1060
      /* Otherwise, factory triming value cannot be retrieved and error       */
1060
    }
1061
      /* status is returned.                                                  */
1061
    else
1062
      trimmingvalue = OPAMP_FACTORYTRIMMING_DUMMY;
1062
    {
1063
    }
1063
      /* Select trimming settings depending on power mode */
1064
    else
1064
      if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
1065
    {
1065
      {
1066
      /* Select trimming settings depending on power mode */
1066
        tmp_opamp_reg_trimming = &OPAMP->OTR;
1067
      if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMAL)
1067
      }
1068
      {
1068
      else
1069
        tmp_opamp_reg_trimming = &OPAMP->OTR;
1069
      {
1070
      }
1070
        tmp_opamp_reg_trimming = &OPAMP->LPOTR;
1071
      else
1071
      }
1072
      {
1072
 
1073
        tmp_opamp_reg_trimming = &OPAMP->LPOTR;
1073
      /* Get factory trimming  */
1074
      }
1074
      trimmingvalue = ((*tmp_opamp_reg_trimming >> OPAMP_OFFSET_TRIM_BITSPOSITION(hopamp, trimmingoffset)) & OPAMP_TRIM_VALUE_MASK);
1075
     
1075
    }
1076
      /* Get factory trimming  */
1076
  }
1077
      trimmingvalue = ((*tmp_opamp_reg_trimming >> OPAMP_OFFSET_TRIM_BITSPOSITION(hopamp, trimmingoffset)) & OPAMP_TRIM_VALUE_MASK);
1077
  else
1078
    }
1078
  {
1079
  }
1079
    return OPAMP_FACTORYTRIMMING_DUMMY;
1080
  else
1080
  }
1081
  {
1081
  return trimmingvalue;
1082
    return OPAMP_FACTORYTRIMMING_DUMMY;
1082
}
1083
  }  
1083
 
1084
  return trimmingvalue;
1084
/**
1085
}
1085
  * @}
1086
 
1086
  */
1087
/**
1087
 
1088
  * @}
1088
 
1089
  */
1089
/** @defgroup OPAMP_Exported_Functions_Group4 Peripheral State functions
1090
 
1090
 *  @brief   Peripheral State functions
1091
 
1091
 *
1092
/** @defgroup OPAMP_Exported_Functions_Group4 Peripheral State functions
1092
@verbatim
1093
 *  @brief   Peripheral State functions
1093
 ===============================================================================
1094
 *
1094
                      ##### Peripheral State functions #####
1095
@verbatim  
1095
 ===============================================================================
1096
 ===============================================================================
1096
    [..]
1097
                      ##### Peripheral State functions #####
1097
    This subsection permits to get in run-time the status of the peripheral.
1098
 ===============================================================================
1098
 
1099
    [..]
1099
@endverbatim
1100
    This subsection permits to get in run-time the status of the peripheral.
1100
  * @{
1101
 
1101
  */
1102
@endverbatim
1102
 
1103
  * @{
1103
/**
1104
  */
1104
  * @brief  Return the OPAMP handle state.
1105
 
1105
  * @param  hopamp OPAMP handle
1106
/**
1106
  * @retval HAL state
1107
  * @brief  Return the OPAMP handle state.
1107
  */
1108
  * @param  hopamp OPAMP handle
1108
HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef* hopamp)
1109
  * @retval HAL state
1109
{
1110
  */
1110
  /* Check the OPAMP handle allocation */
1111
HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef* hopamp)
1111
  if(hopamp == NULL)
1112
{
1112
  {
1113
  /* Check the OPAMP handle allocation */
1113
    return HAL_OPAMP_STATE_RESET;
1114
  if(hopamp == NULL)
1114
  }
1115
  {
1115
 
1116
    return HAL_OPAMP_STATE_RESET;
1116
  /* Check the parameter */
1117
  }
1117
  assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
1118
 
1118
 
1119
  /* Check the parameter */
1119
  return hopamp->State;
1120
  assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
1120
}
1121
 
1121
 
1122
  return hopamp->State;
1122
#if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
1123
}
1123
/**
1124
 
1124
  * @brief  Register a User OPAMP Callback
1125
#if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
1125
  *         To be used instead of the weak (overridden) predefined callback
1126
/**
1126
  * @param hopamp OPAMP handle
1127
  * @brief  Register a User OPAMP Callback
1127
  * @param CallbackID ID of the callback to be registered
1128
  *         To be used instead of the weak (surcharged) predefined callback
1128
  *        This parameter can be one of the following values:
1129
  * @param hopamp OPAMP handle
1129
  *          @arg @ref HAL_OPAMP_MSPINIT_CB_ID       OPAMP MspInit callback ID
1130
  * @param CallbackID ID of the callback to be registered
1130
  *          @arg @ref HAL_OPAMP_MSPDEINIT_CB_ID     OPAMP MspDeInit callback ID
1131
  *        This parameter can be one of the following values:
1131
  * @param pCallback pointer to the Callback function
1132
  *          @arg @ref HAL_OPAMP_MSPINIT_CB_ID       OPAMP MspInit callback ID
1132
  * @retval status
1133
  *          @arg @ref HAL_OPAMP_MSPDEINIT_CB_ID     OPAMP MspDeInit callback ID  
1133
  */
1134
  * @param pCallback pointer to the Callback function
1134
HAL_StatusTypeDef HAL_OPAMP_RegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackID, pOPAMP_CallbackTypeDef pCallback)
1135
  * @retval status
1135
{
1136
  */
1136
  HAL_StatusTypeDef status = HAL_OK;
1137
HAL_StatusTypeDef HAL_OPAMP_RegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackID, pOPAMP_CallbackTypeDef pCallback)
1137
 
1138
{
1138
  if(pCallback == NULL)
1139
  HAL_StatusTypeDef status = HAL_OK;
1139
  {
1140
 
1140
    return HAL_ERROR;
1141
  if(pCallback == NULL)
1141
  }
1142
  {
1142
 
1143
    return HAL_ERROR;
1143
  /* Process locked */
1144
  }
1144
  __HAL_LOCK(hopamp);
1145
 
1145
 
1146
  /* Process locked */
1146
  if(hopamp->State == HAL_OPAMP_STATE_READY)
1147
  __HAL_LOCK(hopamp);
1147
  {
1148
 
1148
    switch (CallbackID)
1149
  if(hopamp->State == HAL_OPAMP_STATE_READY)
1149
    {
1150
  {
1150
    case HAL_OPAMP_MSPINIT_CB_ID :
1151
    switch (CallbackID)
1151
      hopamp->MspInitCallback = pCallback;
1152
    {
1152
      break;
1153
    case HAL_OPAMP_MSPINIT_CB_ID :
1153
    case HAL_OPAMP_MSPDEINIT_CB_ID :
1154
      hopamp->MspInitCallback = pCallback;
1154
      hopamp->MspDeInitCallback = pCallback;
1155
      break;
1155
      break;
1156
    case HAL_OPAMP_MSPDEINIT_CB_ID :
1156
    default :
1157
      hopamp->MspDeInitCallback = pCallback;
1157
      /* Update the error code */
1158
      break;
1158
      // hopamp->ErrorCode |= HAL_OPAMP_ERROR_INVALID_CALLBACK;
1159
    default :
1159
      /* update return status */
1160
      /* Update the error code */
1160
      status =  HAL_ERROR;
1161
      // hopamp->ErrorCode |= HAL_OPAMP_ERROR_INVALID_CALLBACK; 
1161
      break;
1162
      /* update return status */
1162
    }
1163
      status =  HAL_ERROR;
1163
  }
1164
      break;
1164
  else if (hopamp->State == HAL_OPAMP_STATE_RESET)
1165
    }
1165
  {
1166
  }
1166
    switch (CallbackID)
1167
  else if (hopamp->State == HAL_OPAMP_STATE_RESET)
1167
    {
1168
  {
1168
    case HAL_OPAMP_MSPINIT_CB_ID :
1169
    switch (CallbackID)
1169
      hopamp->MspInitCallback = pCallback;
1170
    {
1170
      break;
1171
    case HAL_OPAMP_MSPINIT_CB_ID :
1171
    case HAL_OPAMP_MSPDEINIT_CB_ID :
1172
      hopamp->MspInitCallback = pCallback;
1172
      hopamp->MspDeInitCallback = pCallback;
1173
      break;
1173
      break;
1174
    case HAL_OPAMP_MSPDEINIT_CB_ID :
1174
    default :
1175
      hopamp->MspDeInitCallback = pCallback;
1175
      /* Update the error code */
1176
      break;
1176
      // hopamp->ErrorCode |= HAL_OPAMP_ERROR_INVALID_CALLBACK;
1177
    default :
1177
      /* update return status */
1178
      /* Update the error code */
1178
      status =  HAL_ERROR;
1179
      // hopamp->ErrorCode |= HAL_OPAMP_ERROR_INVALID_CALLBACK; 
1179
      break;
1180
      /* update return status */
1180
    }
1181
      status =  HAL_ERROR;
1181
  }
1182
      break;
1182
  else
1183
    }
1183
  {
1184
  }
1184
    /* update return status */
1185
  else
1185
    status =  HAL_ERROR;
1186
  {
1186
  }
1187
    /* update return status */
1187
 
1188
    status =  HAL_ERROR;
1188
  /* Release Lock */
1189
  }
1189
  __HAL_UNLOCK(hopamp);
1190
 
1190
  return status;
1191
  /* Release Lock */
1191
}
1192
  __HAL_UNLOCK(hopamp);
1192
 
1193
  return status;
1193
/**
1194
}
1194
  * @brief  Unregister a User OPAMP Callback
1195
 
1195
  *         OPAMP Callback is redirected to the weak (overridden) predefined callback
1196
/**
1196
  * @param hopamp OPAMP handle
1197
  * @brief  Unregister a User OPAMP Callback
1197
  * @param CallbackID ID of the callback to be unregistered
1198
  *         OPAMP Callback is redirected to the weak (surcharged) predefined callback
1198
  *        This parameter can be one of the following values:
1199
  * @param hopamp OPAMP handle
1199
  *          @arg @ref HAL_OPAMP_MSPINIT_CB_ID              OPAMP MSP Init Callback ID
1200
  * @param CallbackID ID of the callback to be unregistered
1200
  *          @arg @ref HAL_OPAMP_MSPDEINIT_CB_ID            OPAMP MSP DeInit Callback ID
1201
  *        This parameter can be one of the following values:
1201
  *          @arg @ref HAL_OPAMP_ALL_CB_ID                   OPAMP All Callbacks
1202
  *          @arg @ref HAL_OPAMP_MSPINIT_CB_ID              OPAMP MSP Init Callback ID
1202
  * @retval status
1203
  *          @arg @ref HAL_OPAMP_MSPDEINIT_CB_ID            OPAMP MSP DeInit Callback ID
1203
  */
1204
  *          @arg @ref HAL_OPAMP_ALL_CB_ID                   OPAMP All Callbacks
1204
 
1205
  * @retval status
1205
HAL_StatusTypeDef HAL_OPAMP_UnRegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackID)
1206
  */
1206
{
1207
 
1207
  HAL_StatusTypeDef status = HAL_OK;
1208
HAL_StatusTypeDef HAL_OPAMP_UnRegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackID)
1208
 
1209
{
1209
  /* Process locked */
1210
  HAL_StatusTypeDef status = HAL_OK;
1210
  __HAL_LOCK(hopamp);
1211
 
1211
 
1212
  /* Process locked */
1212
  if(hopamp->State == HAL_OPAMP_STATE_READY)
1213
  __HAL_LOCK(hopamp);
1213
  {
1214
 
1214
    switch (CallbackID)
1215
  if(hopamp->State == HAL_OPAMP_STATE_READY)
1215
    {
1216
  {
1216
      case HAL_OPAMP_MSPINIT_CB_ID :
1217
    switch (CallbackID)
1217
      hopamp->MspInitCallback = HAL_OPAMP_MspInit;
1218
    {    
1218
      break;
1219
      case HAL_OPAMP_MSPINIT_CB_ID :
1219
    case HAL_OPAMP_MSPDEINIT_CB_ID :
1220
      hopamp->MspInitCallback = HAL_OPAMP_MspInit;
1220
      hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
1221
      break;
1221
      break;
1222
    case HAL_OPAMP_MSPDEINIT_CB_ID :
1222
    case HAL_OPAMP_ALL_CB_ID :
1223
      hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
1223
      hopamp->MspInitCallback = HAL_OPAMP_MspInit;
1224
      break;
1224
      hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
1225
    case HAL_OPAMP_ALL_CB_ID :
1225
      break;
1226
      hopamp->MspInitCallback = HAL_OPAMP_MspInit;
1226
    default :
1227
      hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
1227
      /* update return status */
1228
      break;
1228
      status =  HAL_ERROR;
1229
    default :
1229
      break;
1230
      /* update return status */
1230
    }
1231
      status =  HAL_ERROR;
1231
  }
1232
      break;
1232
  else if (hopamp->State == HAL_OPAMP_STATE_RESET)
1233
    }
1233
  {
1234
  }
1234
    switch (CallbackID)
1235
  else if (hopamp->State == HAL_OPAMP_STATE_RESET)
1235
    {
1236
  {
1236
    case HAL_OPAMP_MSPINIT_CB_ID :
1237
    switch (CallbackID)
1237
      hopamp->MspInitCallback = HAL_OPAMP_MspInit;
1238
    {
1238
      break;
1239
    case HAL_OPAMP_MSPINIT_CB_ID :
1239
    case HAL_OPAMP_MSPDEINIT_CB_ID :
1240
      hopamp->MspInitCallback = HAL_OPAMP_MspInit;
1240
      hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
1241
      break;
1241
      break;
1242
    case HAL_OPAMP_MSPDEINIT_CB_ID :
1242
    default :
1243
      hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
1243
      /* update return status */
1244
      break;
1244
      status =  HAL_ERROR;
1245
    default :
1245
      break;
1246
      /* update return status */
1246
    }
1247
      status =  HAL_ERROR;
1247
  }
1248
      break;
1248
  else
1249
    }
1249
  {
1250
  }
1250
    /* update return status */
1251
  else
1251
    status =  HAL_ERROR;
1252
  {
1252
  }
1253
    /* update return status */
1253
 
1254
    status =  HAL_ERROR;
1254
  /* Release Lock */
1255
  }
1255
  __HAL_UNLOCK(hopamp);
1256
 
1256
  return status;
1257
  /* Release Lock */
1257
}
1258
  __HAL_UNLOCK(hopamp);
1258
 
1259
  return status;
1259
#endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
1260
}
1260
/**
1261
 
1261
  * @}
1262
#endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
1262
  */
1263
/**
1263
 
1264
  * @}
1264
/**
1265
  */
1265
  * @}
1266
 
1266
  */
1267
/**
1267
 
1268
  * @}
1268
#endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX || STM32L162xC || STM32L152xC || STM32L151xC */
1269
  */
1269
 
1270
 
1270
#endif /* HAL_OPAMP_MODULE_ENABLED */
1271
#endif /* STM32L151xCA || STM32L151xD || STM32L152xCA || STM32L152xD || STM32L162xCA || STM32L162xD || STM32L151xE || STM32L151xDX || STM32L152xE || STM32L152xDX || STM32L162xE || STM32L162xDX || STM32L162xC || STM32L152xC || STM32L151xC */
1271
/**
1272
 
1272
  * @}
1273
#endif /* HAL_OPAMP_MODULE_ENABLED */
1273
  */
1274
/**
1274
 
1275
  * @}
1275
/**
1276
  */
1276
  * @}
1277
 
1277
  */
1278
/**
1278
 
1279
  * @}
-
 
1280
  */
-
 
1281
 
-
 
1282
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
-