2 ******************************************************************************
3 * @file stm32f3xx_hal_opamp.h
4 * @author MCD Application Team
7 * @brief Header file of OPAMP HAL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F3xx_HAL_OPAMP_H
40 #define __STM32F3xx_HAL_OPAMP_H
46 #if defined(STM32F302xE) || defined(STM32F303xE) || defined(STM32F398xx) || \
47 defined(STM32F302xC) || defined(STM32F303xC) || defined(STM32F358xx) || \
48 defined(STM32F303x8) || defined(STM32F334x8) || defined(STM32F328xx) || \
49 defined(STM32F301x8) || defined(STM32F302x8) || defined(STM32F318xx)
51 /* Includes ------------------------------------------------------------------*/
52 #include "stm32f3xx_hal_def.h"
54 /** @addtogroup STM32F3xx_HAL_Driver
62 /* Exported types ------------------------------------------------------------*/
63 /** @defgroup OPAMP_Exported_Types OPAMP Exported Types
68 * @brief OPAMP Init structure definition
73 uint32_t Mode; /*!< Specifies the OPAMP mode
74 This parameter must be a value of @ref OPAMP_Mode
75 mode is either Standalone, - Follower or PGA */
77 uint32_t InvertingInput; /*!< Specifies the inverting input in Standalone & Pga modes
78 - In Standalone mode: i.e when mode is OPAMP_STANDALONE_MODE
79 This parameter must be a value of @ref OPAMP_InvertingInput
80 InvertingInput is either VM0 or VM1
81 - In PGA mode: i.e when mode is OPAMP_PGA_MODE
82 & in Follower mode i.e when mode is OPAMP_FOLLOWER_MODE
83 This parameter is Not Applicable */
85 uint32_t NonInvertingInput; /*!< Specifies the non inverting input of the opamp:
86 This parameter must be a value of @ref OPAMP_NonInvertingInput
87 NonInvertingInput is either VP0, VP1, VP2 or VP3 */
89 uint32_t TimerControlledMuxmode; /*!< Specifies if the Timer controlled Mux mode is enabled or disabled
90 This parameter must be a value of @ref OPAMP_TimerControlledMuxmode */
92 uint32_t InvertingInputSecondary; /*!< Specifies the inverting input (secondary) of the opamp when
93 TimerControlledMuxmode is enabled
94 i.e. when TimerControlledMuxmode is OPAMP_TIMERCONTROLLEDMUXMODE_ENABLE
95 - In Standalone mode: i.e when mode is OPAMP_STANDALONE_MODE
96 This parameter must be a value of @ref OPAMP_InvertingInputSecondary
97 InvertingInputSecondary is either VM0 or VM1
98 - In PGA mode: i.e when mode is OPAMP_PGA_MODE
99 & in Follower mode i.e when mode is OPAMP_FOLLOWER_MODE
100 This parameter is Not Applicable */
102 uint32_t NonInvertingInputSecondary; /*!< Specifies the non inverting input (secondary) of the opamp when
103 TimerControlledMuxmode is enabled
104 i.e. when TimerControlledMuxmode is OPAMP_TIMERCONTROLLEDMUXMODE_ENABLE
105 This parameter must be a value of @ref OPAMP_NonInvertingInputSecondary
106 NonInvertingInput is either VP0, VP1, VP2 or VP3 */
108 uint32_t PgaConnect; /*!< Specifies the inverting pin in PGA mode
109 i.e. when mode is OPAMP_PGA_MODE
110 This parameter must be a value of @ref OPAMP_PgaConnect
111 Either: not connected, connected to VM0, connected to VM1
112 (VM0 or VM1 are typically used for external filtering) */
114 uint32_t PgaGain; /*!< Specifies the gain in PGA mode
115 i.e. when mode is OPAMP_PGA_MODE.
116 This parameter must be a value of @ref OPAMP_PgaGain (2, 4, 8 or 16 ) */
118 uint32_t UserTrimming; /*!< Specifies the trimming mode
119 This parameter must be a value of @ref OPAMP_UserTrimming
120 UserTrimming is either factory or user trimming */
122 uint32_t TrimmingValueP; /*!< Specifies the offset trimming value (PMOS)
123 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
124 This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
126 uint32_t TrimmingValueN; /*!< Specifies the offset trimming value (NMOS)
127 i.e. when UserTrimming is OPAMP_TRIMMING_USER.
128 This parameter must be a number between Min_Data = 1 and Max_Data = 31 */
133 * @brief HAL State structures definition
138 HAL_OPAMP_STATE_RESET = 0x00000000, /*!< OPMAP is not yet Initialized */
140 HAL_OPAMP_STATE_READY = 0x00000001, /*!< OPAMP is initialized and ready for use */
141 HAL_OPAMP_STATE_CALIBBUSY = 0x00000002, /*!< OPAMP is enabled in auto calibration mode */
143 HAL_OPAMP_STATE_BUSY = 0x00000004, /*!< OPAMP is enabled and running in normal mode */
144 HAL_OPAMP_STATE_BUSYLOCKED = 0x00000005, /*!< OPAMP is locked
145 only system reset allows reconfiguring the opamp. */
147 }HAL_OPAMP_StateTypeDef;
150 * @brief OPAMP Handle Structure definition to @brief OPAMP Handle Structure definition
154 OPAMP_TypeDef *Instance; /*!< OPAMP instance's registers base address */
155 OPAMP_InitTypeDef Init; /*!< OPAMP required parameters */
156 HAL_StatusTypeDef Status; /*!< OPAMP peripheral status */
157 HAL_LockTypeDef Lock; /*!< Locking object */
158 __IO HAL_OPAMP_StateTypeDef State; /*!< OPAMP communication state */
160 } OPAMP_HandleTypeDef;
163 * @brief OPAMP_TrimmingValueTypeDef @brief definition
166 typedef uint32_t OPAMP_TrimmingValueTypeDef;
171 /* Exported constants --------------------------------------------------------*/
172 /** @defgroup OPAMP_Exported_Constants OPAMP Exported Constants
176 /** @defgroup CSR_INIT CSR init register Mask
179 /* Used for Init phase */
180 #define OPAMP_CSR_UPDATE_PARAMETERS_INIT_MASK (OPAMP_CSR_TRIMOFFSETN | OPAMP_CSR_TRIMOFFSETP \
181 | OPAMP_CSR_USERTRIM | OPAMP_CSR_PGGAIN | OPAMP_CSR_VPSSEL \
182 | OPAMP_CSR_VMSSEL | OPAMP_CSR_TCMEN | OPAMP_CSR_VPSEL \
183 | OPAMP_CSR_VPSEL | OPAMP_CSR_FORCEVP)
189 /** @defgroup OPAMP_Mode OPAMP Mode
192 #define OPAMP_STANDALONE_MODE ((uint32_t)0x00000000) /*!< standalone mode */
193 #define OPAMP_PGA_MODE OPAMP_CSR_VMSEL_1 /*!< PGA mode */
194 #define OPAMP_FOLLOWER_MODE OPAMP_CSR_VMSEL /*!< follower mode */
197 #define IS_OPAMP_FUNCTIONAL_NORMALMODE(INPUT) (((INPUT) == OPAMP_STANDALONE_MODE) || \
198 ((INPUT) == OPAMP_PGA_MODE) || \
199 ((INPUT) == OPAMP_FOLLOWER_MODE))
205 /** @defgroup OPAMP_NonInvertingInput OPAMP Non Inverting Input
209 #define OPAMP_NONINVERTINGINPUT_VP0 OPAMP_CSR_VPSEL /*!< VP0 (PA1 for OPAMP1, PA7 for OPAMP2, PB0 for OPAMP3, PB13 for OPAMP4)
210 connected to OPAMPx non inverting input */
211 #define OPAMP_NONINVERTINGINPUT_VP1 ((uint32_t)0x00000000) /*!< VP1 (PA7 for OPAMP1, PD14 for OPAMP2, PB13 for OPAMP3, PD11 for OPAMP4)
212 connected to OPAMPx non inverting input */
213 #define OPAMP_NONINVERTINGINPUT_VP2 OPAMP_CSR_VPSEL_1 /*!< VP2 (PA3 for OPAMP1, PB0 for OPAMP2, PA1 for OPAMP3, PA4 for OPAMP4)
214 connected to OPAMPx non inverting input */
215 #define OPAMP_NONINVERTINGINPUT_VP3 OPAMP_CSR_VPSEL_0 /*!< vp3 (PA5 for OPAMP1, PB14 for OPAMP2, PA5 for OPAMP3, PB11 for OPAMP4)
216 connected to OPAMPx non inverting input */
218 #define IS_OPAMP_NONINVERTING_INPUT(INPUT) (((INPUT) == OPAMP_NONINVERTINGINPUT_VP0) || \
219 ((INPUT) == OPAMP_NONINVERTINGINPUT_VP1) || \
220 ((INPUT) == OPAMP_NONINVERTINGINPUT_VP2) || \
221 ((INPUT) == OPAMP_NONINVERTINGINPUT_VP3))
227 /** @defgroup OPAMP_InvertingInput OPAMP Inverting Input
231 #define IOPAMP_INVERTINGINPUT_VM0 ((uint32_t)0x00000000) /*!< inverting input connected to VM0 */
232 #define IOPAMP_INVERTINGINPUT_VM1 OPAMP_CSR_VMSEL_0 /*!< inverting input connected to VM1 */
234 #define IS_OPAMP_INVERTING_INPUT(INPUT) (((INPUT) == IOPAMP_INVERTINGINPUT_VM0) || \
235 ((INPUT) == IOPAMP_INVERTINGINPUT_VM1))
241 /** @defgroup OPAMP_TimerControlledMuxmode OPAMP Timer Controlled Mux mode
244 #define OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE ((uint32_t)0x00000000) /*!< Timer controlled Mux mode disabled */
245 #define OPAMP_TIMERCONTROLLEDMUXMODE_ENABLE OPAMP_CSR_TCMEN /*!< Timer controlled Mux mode enabled */
247 #define IS_OPAMP_TIMERCONTROLLED_MUXMODE(MUXMODE) (((MUXMODE) == OPAMP_TIMERCONTROLLEDMUXMODE_DISABLE) || \
248 ((MUXMODE) == OPAMP_TIMERCONTROLLEDMUXMODE_ENABLE))
253 /** @defgroup OPAMP_NonInvertingInputSecondary OPAMP Non Inverting Input Secondary
257 #define OPAMP_SEC_NONINVERTINGINPUT_VP0 OPAMP_CSR_VPSSEL /*!< VP0 (PA1 for OPAMP1, PA7 for OPAMP2, PB0 for OPAMP3, PB13 for OPAMP4)
258 connected to OPAMPx non inverting input */
259 #define OPAMP_SEC_NONINVERTINGINPUT_VP1 ((uint32_t)0x00000000) /*!< VP1 (PA7 for OPAMP1, PD14 for OPAMP2, PB13 for OPAMP3, PD11 for OPAMP4)
260 connected to OPAMPx non inverting input */
261 #define OPAMP_SEC_NONINVERTINGINPUT_VP2 OPAMP_CSR_VPSSEL_1 /*!< VP2 (PA3 for OPAMP1, PB0 for OPAMP2, PA1 for OPAMP3, PA4 for OPAMP4)
262 connected to OPAMPx non inverting input */
263 #define OPAMP_SEC_NONINVERTINGINPUT_VP3 OPAMP_CSR_VPSSEL_0 /*!< VP3 (PA5 for OPAMP1, PB14 for OPAMP2, PA5 for OPAMP3, PB11 for OPAMP4)
264 connected to OPAMPx non inverting input */
266 #define IS_OPAMP_SEC_NONINVERTINGINPUT(INPUT) (((INPUT) == OPAMP_SEC_NONINVERTINGINPUT_VP0) || \
267 ((INPUT) == OPAMP_SEC_NONINVERTINGINPUT_VP1) || \
268 ((INPUT) == OPAMP_SEC_NONINVERTINGINPUT_VP2) || \
269 ((INPUT) == OPAMP_SEC_NONINVERTINGINPUT_VP3))
275 /** @defgroup OPAMP_InvertingInputSecondary OPAMP Inverting Input Secondary
279 #define OPAMP_SEC_INVERTINGINPUT_VM0 ((uint32_t)0x00000000) /*!< VM0 (PC5 for OPAMP1 and OPAMP2, PB10 for OPAMP3 and OPAMP4)
280 connected to OPAMPx inverting input */
281 #define OPAMP_SEC_INVERTINGINPUT_VM1 OPAMP_CSR_VMSSEL /*!< VM1 (PA3 for OPAMP1, PA5 for OPAMP2, PB2 for OPAMP3, PD8 for OPAMP4)
282 connected to OPAMPx inverting input */
284 #define IS_OPAMP_SEC_INVERTINGINPUT(INPUT) (((INPUT) == OPAMP_SEC_INVERTINGINPUT_VM0) || \
285 ((INPUT) == OPAMP_SEC_INVERTINGINPUT_VM1))
291 /** @defgroup OPAMP_PgaConnect OPAMP Pga Connect
295 #define OPAMP_PGACONNECT_NO ((uint32_t)0x00000000) /*!< In PGA mode, the non inverting input is not connected */
296 #define OPAMP_PGACONNECT_VM0 OPAMP_CSR_PGGAIN_3 /*!< In PGA mode, the non inverting input is connected to VM0 */
297 #define OPAMP_PGACONNECT_VM1 (OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_3) /*!< In PGA mode, the non inverting input is connected to VM1 */
299 #define IS_OPAMP_PGACONNECT(CONNECT) (((CONNECT) == OPAMP_PGACONNECT_NO) || \
300 ((CONNECT) == OPAMP_PGACONNECT_VM0) || \
301 ((CONNECT) == OPAMP_PGACONNECT_VM1))
307 /** @defgroup OPAMP_PgaGain OPAMP Pga Gain
311 #define OPAMP_PGA_GAIN_2 ((uint32_t)0x00000000) /*!< PGA gain = 2 */
312 #define OPAMP_PGA_GAIN_4 OPAMP_CSR_PGGAIN_0 /*!< PGA gain = 4 */
313 #define OPAMP_PGA_GAIN_8 OPAMP_CSR_PGGAIN_1 /*!< PGA gain = 8 */
314 #define OPAMP_PGA_GAIN_16 (OPAMP_CSR_PGGAIN_0 | OPAMP_CSR_PGGAIN_1) /*!< PGA gain = 16 */
316 #define IS_OPAMP_PGA_GAIN(GAIN) (((GAIN) == OPAMP_PGA_GAIN_2) || \
317 ((GAIN) == OPAMP_PGA_GAIN_4) || \
318 ((GAIN) == OPAMP_PGA_GAIN_8) || \
319 ((GAIN) == OPAMP_PGA_GAIN_16))
324 /** @defgroup OPAMP_UserTrimming OPAMP User Trimming
328 #define OPAMP_TRIMMING_FACTORY ((uint32_t)0x00000000) /*!< Factory trimming */
329 #define OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< User trimming */
331 #define IS_OPAMP_TRIMMING(TRIMMING) (((TRIMMING) == OPAMP_TRIMMING_FACTORY) || \
332 ((TRIMMING) == OPAMP_TRIMMING_USER))
334 /** @defgroup OPAMP_FactoryTrimming OPAMP Factory Trimming
338 #define OPAMP_FACTORYTRIMMING_DUMMY ((uint32_t)0xFFFFFFFF) /*!< Dummy trimming value */
340 #define OPAMP_FACTORYTRIMMING_N ((uint32_t)0x00000000) /*!< Offset trimming N */
341 #define OPAMP_FACTORYTRIMMING_P ((uint32_t)0x00000001) /*!< Offset trimming P */
343 #define IS_OPAMP_FACTORYTRIMMING(TRIMMING) (((TRIMMING) == OPAMP_FACTORYTRIMMING_N) || \
344 ((TRIMMING) == OPAMP_FACTORYTRIMMING_P))
351 /** @defgroup OPAMP_TrimmingValue OPAMP Trimming Value
355 #define IS_OPAMP_TRIMMINGVALUE(TRIMMINGVALUE) ((TRIMMINGVALUE) <= 0x1F)
363 /** @defgroup OPAMP_Input OPAMP Input
367 #define OPAMP_INPUT_INVERTING ((uint32_t) 24) /*!< Inverting input */
368 #define OPAMP_INPUT_NONINVERTING ((uint32_t) 19) /*!< Non inverting input */
370 #define IS_OPAMP_INPUT(INPUT) (((INPUT) == OPAMP_INPUT_INVERTING) || \
371 ((INPUT) == OPAMP_INPUT_NONINVERTING))
377 /** @defgroup OPAMP_VREF OPAMP VREF
381 #define OPAMP_VREF_3VDDA ((uint32_t)0x00000000) /*!< OPMAP Vref = 3.3% VDDA */
382 #define OPAMP_VREF_10VDDA OPAMP_CSR_CALSEL_0 /*!< OPMAP Vref = 10% VDDA */
383 #define OPAMP_VREF_50VDDA OPAMP_CSR_CALSEL_1 /*!< OPMAP Vref = 50% VDDA */
384 #define OPAMP_VREF_90VDDA OPAMP_CSR_CALSEL /*!< OPMAP Vref = 90% VDDA */
386 #define IS_OPAMP_VREF(VREF) (((VREF) == OPAMP_VREF_3VDDA) || \
387 ((VREF) == OPAMP_VREF_10VDDA) || \
388 ((VREF) == OPAMP_VREF_50VDDA) || \
389 ((VREF) == OPAMP_VREF_90VDDA))
395 /** @defgroup OPAMP_Vref2ADCforCalib OPAMP Vref2ADCforCalib
398 #define OPAMP_VREF_NOTCONNECTEDTO_ADC ((uint32_t)0x00000000) /*!< VREF not connected to ADC */
399 #define OPAMP_VREF_CONNECTEDTO_ADC ((uint32_t)0x00000001) /*!< VREF not connected to ADC */
401 #define IS_OPAMP_ALLOPAMPVREF_CONNECT(CONNECT) (((CONNECT) == OPAMP_VREF_NOTCONNECTEDTO_ADC) || \
402 ((CONNECT) == OPAMP_VREF_CONNECTEDTO_ADC))
413 /* Exported macros -----------------------------------------------------------*/
414 /** @defgroup OPAMP_Exported_Macros OPAMP Exported Macros
418 /** @brief Reset OPAMP handle state
419 * @param __HANDLE__: OPAMP handle.
422 #define __HAL_OPAMP_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_OPAMP_STATE_RESET)
428 /* Include OPAMP HAL Extended module */
429 #include "stm32f3xx_hal_opamp_ex.h"
431 /* Exported functions --------------------------------------------------------*/
432 /** @defgroup OPAMP_Exported_Functions OPAMP Exported Functions
436 /** @defgroup OPAMP_Exported_Functions_Group1 Initialization and de-initialization functions
440 /* Initialization/de-initialization functions **********************************/
441 HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp);
442 HAL_StatusTypeDef HAL_OPAMP_DeInit (OPAMP_HandleTypeDef *hopamp);
443 void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp);
444 void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp);
450 /** @defgroup OPAMP_Exported_Functions_Group2 Input and Output operation functions
454 /* I/O operation functions *****************************************************/
455 HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp);
456 HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp);
457 HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp);
463 /** @defgroup OPAMP_Exported_Functions_Group3 Peripheral Control functions
467 /* Peripheral Control functions ************************************************/
468 HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp);
474 /** @defgroup OPAMP_Exported_Functions_Group4 Peripheral State functions
478 /* Peripheral State functions **************************************************/
479 HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp);
480 OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset);
498 #endif /* STM32F302xE || STM32F303xE || STM32F398xx || */
499 /* STM32F302xC || STM32F303xC || STM32F358xx || */
500 /* STM32F303x8 || STM32F334x8 || STM32F328xx || */
501 /* STM32F301x8 || STM32F302x8 || STM32F318xx */
507 #endif /* __STM32F3xx_HAL_OPAMP_H */
509 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/