stm32l1xx_hal_opamp.c 43 KB

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