stm32l4xx_hal_opamp.c 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_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) peripheral:
  8. * + Initialization and de-initialization functions
  9. * + IO operation functions
  10. * + Peripheral Control functions
  11. * + Peripheral State functions
  12. *
  13. ******************************************************************************
  14. * @attention
  15. *
  16. * Copyright (c) 2017 STMicroelectronics.
  17. * All rights reserved.
  18. *
  19. * This software is licensed under terms that can be found in the LICENSE file
  20. * in the root directory of this software component.
  21. * If no LICENSE file comes with this software, it is provided AS-IS.
  22. *
  23. ******************************************************************************
  24. @verbatim
  25. ================================================================================
  26. ##### OPAMP Peripheral Features #####
  27. ================================================================================
  28. [..] The device integrates 1 or 2 operational amplifiers OPAMP1 & OPAMP2
  29. (#) The OPAMP(s) provide(s) several exclusive running modes.
  30. (++) 1 OPAMP: STM32L412xx STM32L422xx STM32L431xx STM32L432xx STM32L433xx STM32L442xx STM32L443xx
  31. (++) 2 OPAMP: STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx
  32. (#) The OPAMP(s) provide(s) several exclusive running modes.
  33. (++) Standalone mode
  34. (++) Programmable Gain Amplifier (PGA) mode (Resistor feedback output)
  35. (++) Follower mode
  36. (#) All OPAMP (same for all OPAMPs) can operate in
  37. (++) Either Low range (VDDA < 2.4V) power supply
  38. (++) Or High range (VDDA > 2.4V) power supply
  39. (#) Each OPAMP(s) can be configured in normal and low power mode.
  40. (#) The OPAMP(s) provide(s) calibration capabilities.
  41. (++) Calibration aims at correcting some offset for running mode.
  42. (++) The OPAMP uses either factory calibration settings OR user defined
  43. calibration (trimming) settings (i.e. trimming mode).
  44. (++) The user defined settings can be figured out using self calibration
  45. handled by HAL_OPAMP_SelfCalibrate, HAL_OPAMPEx_SelfCalibrateAll
  46. (++) HAL_OPAMP_SelfCalibrate:
  47. (+++) Runs automatically the calibration.
  48. (+++) Enables the user trimming mode
  49. (+++) Updates the init structure with trimming values with fresh calibration
  50. results.
  51. The user may store the calibration results for larger
  52. (ex monitoring the trimming as a function of temperature
  53. for instance)
  54. (+++) HAL_OPAMPEx_SelfCalibrateAll
  55. runs calibration of all OPAMPs in parallel to save search time.
  56. (#) Running mode: Standalone mode
  57. (++) Gain is set externally (gain depends on external loads).
  58. (++) Follower mode also possible externally by connecting the inverting input to
  59. the output.
  60. (#) Running mode: Follower mode
  61. (++) No Inverting Input is connected.
  62. (#) Running mode: Programmable Gain Amplifier (PGA) mode
  63. (Resistor feedback output)
  64. (++) The OPAMP(s) output(s) can be internally connected to resistor feedback
  65. output.
  66. (++) OPAMP gain is either 2, 4, 8 or 16.
  67. (#) The OPAMPs inverting input can be selected according to the Reference Manual
  68. "OPAMP function description" chapter.
  69. (#) The OPAMPs non inverting input can be selected according to the Reference Manual
  70. "OPAMP function description" chapter.
  71. ##### How to use this driver #####
  72. ================================================================================
  73. [..]
  74. *** Power supply range ***
  75. ============================================
  76. [..] To run in low power mode:
  77. (#) Configure the OPAMP using HAL_OPAMP_Init() function:
  78. (++) Select OPAMP_POWERSUPPLY_LOW (VDDA lower than 2.4V)
  79. (++) Otherwise select OPAMP_POWERSUPPLY_HIGH (VDDA higher than 2.4V)
  80. *** Low / normal power mode ***
  81. ============================================
  82. [..] To run in low power mode:
  83. (#) Configure the OPAMP using HAL_OPAMP_Init() function:
  84. (++) Select OPAMP_POWERMODE_LOWPOWER
  85. (++) Otherwise select OPAMP_POWERMODE_NORMALPOWER
  86. *** Calibration ***
  87. ============================================
  88. [..] To run the OPAMP calibration self calibration:
  89. (#) Start calibration using HAL_OPAMP_SelfCalibrate.
  90. Store the calibration results.
  91. *** Running mode ***
  92. ============================================
  93. [..] To use the OPAMP, perform the following steps:
  94. (#) Fill in the HAL_OPAMP_MspInit() to
  95. (++) Enable the OPAMP Peripheral clock using macro __HAL_RCC_OPAMP_CLK_ENABLE()
  96. (++) Configure the OPAMP input AND output in analog mode using
  97. HAL_GPIO_Init() to map the OPAMP output to the GPIO pin.
  98. (#) Registrate Callbacks
  99. (++) The compilation define USE_HAL_OPAMP_REGISTER_CALLBACKS when set to 1
  100. allows the user to configure dynamically the driver callbacks.
  101. (++) Use Functions HAL_OPAMP_RegisterCallback() to register a user callback,
  102. it allows to register following callbacks:
  103. (+++) MspInitCallback : OPAMP MspInit.
  104. (+++) MspDeInitCallback : OPAMP MspFeInit.
  105. This function takes as parameters the HAL peripheral handle, the Callback ID
  106. and a pointer to the user callback function.
  107. (++) Use function HAL_OPAMP_UnRegisterCallback() to reset a callback to the default
  108. weak (overridden) function. It allows to reset following callbacks:
  109. (+++) MspInitCallback : OPAMP MspInit.
  110. (+++) MspDeInitCallback : OPAMP MspdeInit.
  111. (+++) All Callbacks
  112. (#) Configure the OPAMP using HAL_OPAMP_Init() function:
  113. (++) Select the mode
  114. (++) Select the inverting input
  115. (++) Select the non-inverting input
  116. (++) If PGA mode is enabled, Select if inverting input is connected.
  117. (++) Select either factory or user defined trimming mode.
  118. (++) If the user-defined trimming mode is enabled, select PMOS & NMOS trimming values
  119. (typically values set by HAL_OPAMP_SelfCalibrate function).
  120. (#) Enable the OPAMP using HAL_OPAMP_Start() function.
  121. (#) Disable the OPAMP using HAL_OPAMP_Stop() function.
  122. (#) Lock the OPAMP in running mode using HAL_OPAMP_Lock() function.
  123. Caution: On STM32L4, HAL OPAMP lock is software lock only (not
  124. hardware lock as on some other STM32 devices)
  125. (#) If needed, unlock the OPAMP using HAL_OPAMPEx_Unlock() function.
  126. *** Running mode: change of configuration while OPAMP ON ***
  127. ============================================
  128. [..] To Re-configure OPAMP when OPAMP is ON (change on the fly)
  129. (#) If needed, fill in the HAL_OPAMP_MspInit()
  130. (++) This is the case for instance if you wish to use new OPAMP I/O
  131. (#) Configure the OPAMP using HAL_OPAMP_Init() function:
  132. (++) As in configure case, select first the parameters you wish to modify.
  133. (#) Change from low power mode to normal power mode (& vice versa) requires
  134. first HAL_OPAMP_DeInit() (force OPAMP OFF) and then HAL_OPAMP_Init().
  135. In other words, of OPAMP is ON, HAL_OPAMP_Init can NOT change power mode
  136. alone.
  137. @endverbatim
  138. ******************************************************************************
  139. Table 1. OPAMPs inverting/non-inverting inputs for the STM32L4 devices:
  140. +------------------------------------------------------------------------|
  141. | | | OPAMP1 | OPAMP2 |
  142. |-----------------|---------|----------------------|---------------------|
  143. | Inverting Input | VM_SEL | | |
  144. | | | IO0-> PA1 | IO0-> PA7 |
  145. | | | LOW LEAKAGE IO (2) | LOW LEAKAGE IO (2) |
  146. | | | Not connected | Not connected |
  147. | (1) | | PGA mode only | PGA mode only |
  148. |-----------------|---------|----------------------|---------------------|
  149. | Non Inverting | VP_SEL | | |
  150. | | | IO0-> PA0 (GPIO) | IO0-> PA6 (GPIO) |
  151. | Input | | DAC1_OUT1 internal | DAC1_OUT2 internal |
  152. +------------------------------------------------------------------------|
  153. (1): NA in follower mode.
  154. (2): Available on some package only (ex. BGA132).
  155. Table 2. OPAMPs outputs for the STM32L4 devices:
  156. +-------------------------------------------------------------------------
  157. | | | OPAMP1 | OPAMP2 |
  158. |-----------------|--------|-----------------------|---------------------|
  159. | Output | VOUT | PA3 | PB0 |
  160. | | | & (1) ADC12_IN if | & (1) ADC12_IN if |
  161. | | | connected internally | connected internally|
  162. |-----------------|--------|-----------------------|---------------------|
  163. (1): ADC1 or ADC2 shall select IN15.
  164. */
  165. /* Includes ------------------------------------------------------------------*/
  166. #include "stm32l4xx_hal.h"
  167. /** @addtogroup STM32L4xx_HAL_Driver
  168. * @{
  169. */
  170. /** @defgroup OPAMP OPAMP
  171. * @brief OPAMP module driver
  172. * @{
  173. */
  174. #ifdef HAL_OPAMP_MODULE_ENABLED
  175. /* Private types -------------------------------------------------------------*/
  176. /* Private variables ---------------------------------------------------------*/
  177. /* Private constants ---------------------------------------------------------*/
  178. /** @addtogroup OPAMP_Private_Constants
  179. * @{
  180. */
  181. /* CSR register reset value */
  182. #define OPAMP_CSR_RESET_VALUE ((uint32_t)0x00000000)
  183. #define OPAMP_CSR_RESET_BITS (OPAMP_CSR_OPAMPxEN | OPAMP_CSR_OPALPM | OPAMP_CSR_OPAMODE \
  184. | OPAMP_CSR_PGGAIN | OPAMP_CSR_VMSEL | OPAMP_CSR_VPSEL \
  185. | OPAMP_CSR_CALON | OPAMP_CSR_USERTRIM)
  186. /* CSR Init masks */
  187. #define OPAMP_CSR_INIT_MASK_PGA (OPAMP_CSR_OPALPM | OPAMP_CSR_OPAMODE| OPAMP_CSR_PGGAIN \
  188. | OPAMP_CSR_VMSEL | OPAMP_CSR_VPSEL | OPAMP_CSR_USERTRIM)
  189. #define OPAMP_CSR_INIT_MASK_FOLLOWER (OPAMP_CSR_OPALPM | OPAMP_CSR_OPAMODE| OPAMP_CSR_VPSEL \
  190. | OPAMP_CSR_USERTRIM)
  191. #define OPAMP_CSR_INIT_MASK_STANDALONE (OPAMP_CSR_OPALPM | OPAMP_CSR_OPAMODE| OPAMP_CSR_VPSEL \
  192. | OPAMP_CSR_VMSEL | OPAMP_CSR_USERTRIM)
  193. /**
  194. * @}
  195. */
  196. /* Private macros ------------------------------------------------------------*/
  197. /* Private functions ---------------------------------------------------------*/
  198. /* Exported functions --------------------------------------------------------*/
  199. /** @defgroup OPAMP_Exported_Functions OPAMP Exported Functions
  200. * @{
  201. */
  202. /** @defgroup OPAMP_Exported_Functions_Group1 Initialization and de-initialization functions
  203. * @brief Initialization and Configuration functions
  204. *
  205. @verbatim
  206. ==============================================================================
  207. ##### Initialization and de-initialization functions #####
  208. ==============================================================================
  209. @endverbatim
  210. * @{
  211. */
  212. /**
  213. * @brief Initializes the OPAMP according to the specified
  214. * parameters in the OPAMP_InitTypeDef and initialize the associated handle.
  215. * @note If the selected opamp is locked, initialization can't be performed.
  216. * To unlock the configuration, perform a system reset.
  217. * @param hopamp OPAMP handle
  218. * @retval HAL status
  219. */
  220. HAL_StatusTypeDef HAL_OPAMP_Init(OPAMP_HandleTypeDef *hopamp)
  221. {
  222. HAL_StatusTypeDef status = HAL_OK;
  223. uint32_t updateotrlpotr;
  224. /* Check the OPAMP handle allocation and lock status */
  225. /* Init not allowed if calibration is ongoing */
  226. if(hopamp == NULL)
  227. {
  228. return HAL_ERROR;
  229. }
  230. else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
  231. {
  232. return HAL_ERROR;
  233. }
  234. else if(hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
  235. {
  236. return HAL_ERROR;
  237. }
  238. else
  239. {
  240. /* Check the parameter */
  241. assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
  242. /* Set OPAMP parameters */
  243. assert_param(IS_OPAMP_POWER_SUPPLY_RANGE(hopamp->Init.PowerSupplyRange));
  244. assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
  245. assert_param(IS_OPAMP_FUNCTIONAL_NORMALMODE(hopamp->Init.Mode));
  246. assert_param(IS_OPAMP_NONINVERTING_INPUT(hopamp->Init.NonInvertingInput));
  247. #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
  248. if(hopamp->State == HAL_OPAMP_STATE_RESET)
  249. {
  250. if(hopamp->MspInitCallback == NULL)
  251. {
  252. hopamp->MspInitCallback = HAL_OPAMP_MspInit;
  253. }
  254. }
  255. #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
  256. if ((hopamp->Init.Mode) == OPAMP_STANDALONE_MODE)
  257. {
  258. assert_param(IS_OPAMP_INVERTING_INPUT_STANDALONE(hopamp->Init.InvertingInput));
  259. }
  260. if ((hopamp->Init.Mode) == OPAMP_PGA_MODE)
  261. {
  262. assert_param(IS_OPAMP_INVERTING_INPUT_PGA(hopamp->Init.InvertingInput));
  263. }
  264. if ((hopamp->Init.Mode) == OPAMP_PGA_MODE)
  265. {
  266. assert_param(IS_OPAMP_PGA_GAIN(hopamp->Init.PgaGain));
  267. }
  268. assert_param(IS_OPAMP_TRIMMING(hopamp->Init.UserTrimming));
  269. if ((hopamp->Init.UserTrimming) == OPAMP_TRIMMING_USER)
  270. {
  271. if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMALPOWER)
  272. {
  273. assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueP));
  274. assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueN));
  275. }
  276. else
  277. {
  278. assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValuePLowPower));
  279. assert_param(IS_OPAMP_TRIMMINGVALUE(hopamp->Init.TrimmingValueNLowPower));
  280. }
  281. }
  282. if(hopamp->State == HAL_OPAMP_STATE_RESET)
  283. {
  284. /* Allocate lock resource and initialize it */
  285. hopamp->Lock = HAL_UNLOCKED;
  286. }
  287. #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
  288. hopamp->MspInitCallback(hopamp);
  289. #else
  290. /* Call MSP init function */
  291. HAL_OPAMP_MspInit(hopamp);
  292. #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
  293. /* Set operating mode */
  294. CLEAR_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALON);
  295. if (hopamp->Init.Mode == OPAMP_PGA_MODE)
  296. {
  297. MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_INIT_MASK_PGA, \
  298. hopamp->Init.PowerMode | \
  299. hopamp->Init.Mode | \
  300. hopamp->Init.PgaGain | \
  301. hopamp->Init.InvertingInput | \
  302. hopamp->Init.NonInvertingInput | \
  303. hopamp->Init.UserTrimming);
  304. }
  305. if (hopamp->Init.Mode == OPAMP_FOLLOWER_MODE)
  306. {
  307. /* In Follower mode InvertingInput is Not Applicable */
  308. MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_INIT_MASK_FOLLOWER, \
  309. hopamp->Init.PowerMode | \
  310. hopamp->Init.Mode | \
  311. hopamp->Init.NonInvertingInput | \
  312. hopamp->Init.UserTrimming);
  313. }
  314. if (hopamp->Init.Mode == OPAMP_STANDALONE_MODE)
  315. {
  316. MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_INIT_MASK_STANDALONE, \
  317. hopamp->Init.PowerMode | \
  318. hopamp->Init.Mode | \
  319. hopamp->Init.InvertingInput | \
  320. hopamp->Init.NonInvertingInput | \
  321. hopamp->Init.UserTrimming);
  322. }
  323. if (hopamp->Init.UserTrimming == OPAMP_TRIMMING_USER)
  324. {
  325. /* Set power mode and associated calibration parameters */
  326. if (hopamp->Init.PowerMode != OPAMP_POWERMODE_LOWPOWER)
  327. {
  328. /* OPAMP_POWERMODE_NORMALPOWER */
  329. /* Set calibration mode (factory or user) and values for */
  330. /* transistors differential pair high (PMOS) and low (NMOS) for */
  331. /* normal mode. */
  332. updateotrlpotr = (((hopamp->Init.TrimmingValueP) << (OPAMP_INPUT_NONINVERTING)) \
  333. | (hopamp->Init.TrimmingValueN));
  334. MODIFY_REG(hopamp->Instance->OTR, OPAMP_OTR_TRIMOFFSETN | OPAMP_OTR_TRIMOFFSETP, updateotrlpotr);
  335. }
  336. else
  337. {
  338. /* OPAMP_POWERMODE_LOWPOWER */
  339. /* transistors differential pair high (PMOS) and low (NMOS) for */
  340. /* low power mode. */
  341. updateotrlpotr = (((hopamp->Init.TrimmingValuePLowPower) << (OPAMP_INPUT_NONINVERTING)) \
  342. | (hopamp->Init.TrimmingValueNLowPower));
  343. MODIFY_REG(hopamp->Instance->LPOTR, OPAMP_OTR_TRIMOFFSETN | OPAMP_OTR_TRIMOFFSETP, updateotrlpotr);
  344. }
  345. }
  346. /* Configure the power supply range */
  347. /* The OPAMP_CSR_OPARANGE is common configuration for all OPAMPs */
  348. /* bit OPAMP1_CSR_OPARANGE is used for both OPAMPs */
  349. MODIFY_REG(OPAMP1->CSR, OPAMP1_CSR_OPARANGE, hopamp->Init.PowerSupplyRange);
  350. /* Update the OPAMP state*/
  351. if (hopamp->State == HAL_OPAMP_STATE_RESET)
  352. {
  353. /* From RESET state to READY State */
  354. hopamp->State = HAL_OPAMP_STATE_READY;
  355. }
  356. /* else: remain in READY or BUSY state (no update) */
  357. return status;
  358. }
  359. }
  360. /**
  361. * @brief DeInitialize the OPAMP peripheral.
  362. * @note Deinitialization can be performed if the OPAMP configuration is locked.
  363. * (the lock is SW in L4)
  364. * @param hopamp OPAMP handle
  365. * @retval HAL status
  366. */
  367. HAL_StatusTypeDef HAL_OPAMP_DeInit(OPAMP_HandleTypeDef *hopamp)
  368. {
  369. HAL_StatusTypeDef status = HAL_OK;
  370. /* Check the OPAMP handle allocation */
  371. /* DeInit not allowed if calibration is ongoing */
  372. if(hopamp == NULL)
  373. {
  374. status = HAL_ERROR;
  375. }
  376. else if(hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
  377. {
  378. status = HAL_ERROR;
  379. }
  380. else
  381. {
  382. /* Check the parameter */
  383. assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
  384. /* Set OPAMP_CSR register to reset value */
  385. /* Mind that OPAMP1_CSR_OPARANGE of CSR of OPAMP1 remains unchanged (applies to both OPAMPs) */
  386. /* OPAMP shall be disabled first separately */
  387. CLEAR_BIT(hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
  388. MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_RESET_BITS, OPAMP_CSR_RESET_VALUE);
  389. #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
  390. if(hopamp->MspDeInitCallback == NULL)
  391. {
  392. hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
  393. }
  394. /* DeInit the low level hardware */
  395. hopamp->MspDeInitCallback(hopamp);
  396. #else
  397. /* DeInit the low level hardware: GPIO, CLOCK and NVIC */
  398. HAL_OPAMP_MspDeInit(hopamp);
  399. #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
  400. /* Update the OPAMP state*/
  401. hopamp->State = HAL_OPAMP_STATE_RESET;
  402. /* Process unlocked */
  403. __HAL_UNLOCK(hopamp);
  404. }
  405. return status;
  406. }
  407. /**
  408. * @brief Initialize the OPAMP MSP.
  409. * @param hopamp OPAMP handle
  410. * @retval None
  411. */
  412. __weak void HAL_OPAMP_MspInit(OPAMP_HandleTypeDef *hopamp)
  413. {
  414. /* Prevent unused argument(s) compilation warning */
  415. UNUSED(hopamp);
  416. /* NOTE : This function should not be modified, when the callback is needed,
  417. the function "HAL_OPAMP_MspInit()" must be implemented in the user file.
  418. */
  419. }
  420. /**
  421. * @brief DeInitialize OPAMP MSP.
  422. * @param hopamp OPAMP handle
  423. * @retval None
  424. */
  425. __weak void HAL_OPAMP_MspDeInit(OPAMP_HandleTypeDef *hopamp)
  426. {
  427. /* Prevent unused argument(s) compilation warning */
  428. UNUSED(hopamp);
  429. /* NOTE : This function should not be modified, when the callback is needed,
  430. the function "HAL_OPAMP_MspDeInit()" must be implemented in the user file.
  431. */
  432. }
  433. /**
  434. * @}
  435. */
  436. /** @defgroup OPAMP_Exported_Functions_Group2 IO operation functions
  437. * @brief IO operation functions
  438. *
  439. @verbatim
  440. ===============================================================================
  441. ##### IO operation functions #####
  442. ===============================================================================
  443. [..]
  444. This subsection provides a set of functions allowing to manage the OPAMP
  445. start, stop and calibration actions.
  446. @endverbatim
  447. * @{
  448. */
  449. /**
  450. * @brief Start the OPAMP.
  451. * @param hopamp OPAMP handle
  452. * @retval HAL status
  453. */
  454. HAL_StatusTypeDef HAL_OPAMP_Start(OPAMP_HandleTypeDef *hopamp)
  455. {
  456. HAL_StatusTypeDef status = HAL_OK;
  457. /* Check the OPAMP handle allocation */
  458. /* Check if OPAMP locked */
  459. if(hopamp == NULL)
  460. {
  461. status = HAL_ERROR;
  462. }
  463. else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
  464. {
  465. status = HAL_ERROR;
  466. }
  467. else
  468. {
  469. /* Check the parameter */
  470. assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
  471. if(hopamp->State == HAL_OPAMP_STATE_READY)
  472. {
  473. /* Enable the selected opamp */
  474. SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
  475. /* Update the OPAMP state*/
  476. /* From HAL_OPAMP_STATE_READY to HAL_OPAMP_STATE_BUSY */
  477. hopamp->State = HAL_OPAMP_STATE_BUSY;
  478. }
  479. else
  480. {
  481. status = HAL_ERROR;
  482. }
  483. }
  484. return status;
  485. }
  486. /**
  487. * @brief Stop the OPAMP.
  488. * @param hopamp OPAMP handle
  489. * @retval HAL status
  490. */
  491. HAL_StatusTypeDef HAL_OPAMP_Stop(OPAMP_HandleTypeDef *hopamp)
  492. {
  493. HAL_StatusTypeDef status = HAL_OK;
  494. /* Check the OPAMP handle allocation */
  495. /* Check if OPAMP locked */
  496. /* Check if OPAMP calibration ongoing */
  497. if(hopamp == NULL)
  498. {
  499. status = HAL_ERROR;
  500. }
  501. else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
  502. {
  503. status = HAL_ERROR;
  504. }
  505. else if(hopamp->State == HAL_OPAMP_STATE_CALIBBUSY)
  506. {
  507. status = HAL_ERROR;
  508. }
  509. else
  510. {
  511. /* Check the parameter */
  512. assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
  513. if(hopamp->State == HAL_OPAMP_STATE_BUSY)
  514. {
  515. /* Disable the selected opamp */
  516. CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
  517. /* Update the OPAMP state*/
  518. /* From HAL_OPAMP_STATE_BUSY to HAL_OPAMP_STATE_READY*/
  519. hopamp->State = HAL_OPAMP_STATE_READY;
  520. }
  521. else
  522. {
  523. status = HAL_ERROR;
  524. }
  525. }
  526. return status;
  527. }
  528. /**
  529. * @brief Run the self calibration of one OPAMP.
  530. * @note Calibration is performed in the mode specified in OPAMP init
  531. * structure (mode normal or low-power). To perform calibration for
  532. * both modes, repeat this function twice after OPAMP init structure
  533. * accordingly updated.
  534. * @note Calibration runs about 10 ms.
  535. * @param hopamp handle
  536. * @retval Updated offset trimming values (PMOS & NMOS), user trimming is enabled
  537. * @retval HAL status
  538. */
  539. HAL_StatusTypeDef HAL_OPAMP_SelfCalibrate(OPAMP_HandleTypeDef *hopamp)
  540. {
  541. HAL_StatusTypeDef status = HAL_OK;
  542. uint32_t trimmingvaluen;
  543. uint32_t trimmingvaluep;
  544. uint32_t delta;
  545. uint32_t opampmode;
  546. __IO uint32_t* tmp_opamp_reg_trimming; /* Selection of register of trimming depending on power mode: OTR or LPOTR */
  547. /* Check the OPAMP handle allocation */
  548. /* Check if OPAMP locked */
  549. if(hopamp == NULL)
  550. {
  551. status = HAL_ERROR;
  552. }
  553. else if(hopamp->State == HAL_OPAMP_STATE_BUSYLOCKED)
  554. {
  555. status = HAL_ERROR;
  556. }
  557. else
  558. {
  559. /* Check if OPAMP in calibration mode and calibration not yet enable */
  560. if(hopamp->State == HAL_OPAMP_STATE_READY)
  561. {
  562. /* Check the parameter */
  563. assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
  564. assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
  565. /* Save OPAMP mode as in */
  566. /* STM32L471xx STM32L475xx STM32L476xx STM32L485xx STM32L486xx */
  567. /* the calibration is not working in PGA mode */
  568. opampmode = READ_BIT(hopamp->Instance->CSR,OPAMP_CSR_OPAMODE);
  569. /* Use of standalone mode */
  570. MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_OPAMODE, OPAMP_STANDALONE_MODE);
  571. /* user trimming values are used for offset calibration */
  572. SET_BIT(hopamp->Instance->CSR, OPAMP_CSR_USERTRIM);
  573. /* Select trimming settings depending on power mode */
  574. if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMALPOWER)
  575. {
  576. tmp_opamp_reg_trimming = &hopamp->Instance->OTR;
  577. }
  578. else
  579. {
  580. tmp_opamp_reg_trimming = &hopamp->Instance->LPOTR;
  581. }
  582. /* Enable calibration */
  583. SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALON);
  584. /* 1st calibration - N */
  585. CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALSEL);
  586. /* Enable the selected opamp */
  587. SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
  588. /* Init trimming counter */
  589. /* Medium value */
  590. trimmingvaluen = 16U;
  591. delta = 8U;
  592. while (delta != 0U)
  593. {
  594. /* Set candidate trimming */
  595. /* OPAMP_POWERMODE_NORMALPOWER */
  596. MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen);
  597. /* OFFTRIMmax delay 1 ms as per datasheet (electrical characteristics */
  598. /* Offset trim time: during calibration, minimum time needed between */
  599. /* two steps to have 1 mV accuracy */
  600. HAL_Delay(OPAMP_TRIMMING_DELAY);
  601. if (READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT) != 0U)
  602. {
  603. /* OPAMP_CSR_CALOUT is HIGH try higher trimming */
  604. trimmingvaluen -= delta;
  605. }
  606. else
  607. {
  608. /* OPAMP_CSR_CALOUT is LOW try lower trimming */
  609. trimmingvaluen += delta;
  610. }
  611. /* Divide range by 2 to continue dichotomy sweep */
  612. delta >>= 1U;
  613. }
  614. /* Still need to check if right calibration is current value or one step below */
  615. /* Indeed the first value that causes the OUTCAL bit to change from 0 to 1 */
  616. /* Set candidate trimming */
  617. MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen);
  618. /* OFFTRIMmax delay 1 ms as per datasheet (electrical characteristics */
  619. /* Offset trim time: during calibration, minimum time needed between */
  620. /* two steps to have 1 mV accuracy */
  621. HAL_Delay(OPAMP_TRIMMING_DELAY);
  622. if ((READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT)) == 0U)
  623. {
  624. /* Trimming value is actually one value more */
  625. trimmingvaluen++;
  626. /* Set right trimming */
  627. MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETN, trimmingvaluen);
  628. }
  629. /* 2nd calibration - P */
  630. SET_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALSEL);
  631. /* Init trimming counter */
  632. /* Medium value */
  633. trimmingvaluep = 16U;
  634. delta = 8U;
  635. while (delta != 0U)
  636. {
  637. /* Set candidate trimming */
  638. /* OPAMP_POWERMODE_NORMALPOWER */
  639. MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep<<OPAMP_INPUT_NONINVERTING));
  640. /* OFFTRIMmax delay 1 ms as per datasheet (electrical characteristics */
  641. /* Offset trim time: during calibration, minimum time needed between */
  642. /* two steps to have 1 mV accuracy */
  643. HAL_Delay(OPAMP_TRIMMING_DELAY);
  644. if (READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT) != 0U)
  645. {
  646. /* OPAMP_CSR_CALOUT is HIGH try higher trimming */
  647. trimmingvaluep += delta;
  648. }
  649. else
  650. {
  651. /* OPAMP_CSR_CALOUT is LOW try lower trimming */
  652. trimmingvaluep -= delta;
  653. }
  654. /* Divide range by 2 to continue dichotomy sweep */
  655. delta >>= 1U;
  656. }
  657. /* Still need to check if right calibration is current value or one step below */
  658. /* Indeed the first value that causes the OUTCAL bit to change from 1 to 0 */
  659. /* Set candidate trimming */
  660. MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep<<OPAMP_INPUT_NONINVERTING));
  661. /* OFFTRIMmax delay 1 ms as per datasheet (electrical characteristics */
  662. /* Offset trim time: during calibration, minimum time needed between */
  663. /* two steps to have 1 mV accuracy */
  664. HAL_Delay(OPAMP_TRIMMING_DELAY);
  665. if (READ_BIT(hopamp->Instance->CSR, OPAMP_CSR_CALOUT) != 0U)
  666. {
  667. /* Trimming value is actually one value more */
  668. trimmingvaluep++;
  669. MODIFY_REG(*tmp_opamp_reg_trimming, OPAMP_OTR_TRIMOFFSETP, (trimmingvaluep<<OPAMP_INPUT_NONINVERTING));
  670. }
  671. /* Disable the OPAMP */
  672. CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_OPAMPxEN);
  673. /* Disable calibration & set normal mode (operating mode) */
  674. CLEAR_BIT (hopamp->Instance->CSR, OPAMP_CSR_CALON);
  675. /* Self calibration is successful */
  676. /* Store calibration(user trimming) results in init structure. */
  677. /* Set user trimming mode */
  678. hopamp->Init.UserTrimming = OPAMP_TRIMMING_USER;
  679. /* Affect calibration parameters depending on mode normal/low power */
  680. if (hopamp->Init.PowerMode != OPAMP_POWERMODE_LOWPOWER)
  681. {
  682. /* Write calibration result N */
  683. hopamp->Init.TrimmingValueN = trimmingvaluen;
  684. /* Write calibration result P */
  685. hopamp->Init.TrimmingValueP = trimmingvaluep;
  686. }
  687. else
  688. {
  689. /* Write calibration result N */
  690. hopamp->Init.TrimmingValueNLowPower = trimmingvaluen;
  691. /* Write calibration result P */
  692. hopamp->Init.TrimmingValuePLowPower = trimmingvaluep;
  693. }
  694. /* Restore OPAMP mode after calibration */
  695. MODIFY_REG(hopamp->Instance->CSR, OPAMP_CSR_OPAMODE, opampmode);
  696. }
  697. else
  698. {
  699. /* OPAMP can not be calibrated from this mode */
  700. status = HAL_ERROR;
  701. }
  702. }
  703. return status;
  704. }
  705. /**
  706. * @}
  707. */
  708. /** @defgroup OPAMP_Exported_Functions_Group3 Peripheral Control functions
  709. * @brief Peripheral Control functions
  710. *
  711. @verbatim
  712. ===============================================================================
  713. ##### Peripheral Control functions #####
  714. ===============================================================================
  715. [..]
  716. This subsection provides a set of functions allowing to control the OPAMP data
  717. transfers.
  718. @endverbatim
  719. * @{
  720. */
  721. /**
  722. * @brief Lock the selected OPAMP configuration.
  723. * @note On STM32L4, HAL OPAMP lock is software lock only (in
  724. * contrast of hardware lock available on some other STM32
  725. * devices).
  726. * @param hopamp OPAMP handle
  727. * @retval HAL status
  728. */
  729. HAL_StatusTypeDef HAL_OPAMP_Lock(OPAMP_HandleTypeDef *hopamp)
  730. {
  731. HAL_StatusTypeDef status = HAL_OK;
  732. /* Check the OPAMP handle allocation */
  733. /* Check if OPAMP locked */
  734. /* OPAMP can be locked when enabled and running in normal mode */
  735. /* It is meaningless otherwise */
  736. if(hopamp == NULL)
  737. {
  738. status = HAL_ERROR;
  739. }
  740. else if(hopamp->State == HAL_OPAMP_STATE_BUSY)
  741. {
  742. /* Check the parameter */
  743. assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
  744. /* OPAMP state changed to locked */
  745. hopamp->State = HAL_OPAMP_STATE_BUSYLOCKED;
  746. }
  747. else
  748. {
  749. status = HAL_ERROR;
  750. }
  751. return status;
  752. }
  753. /**
  754. * @brief Return the OPAMP factory trimming value.
  755. * @note On STM32L4 OPAMP, user can retrieve factory trimming if
  756. * OPAMP has never been set to user trimming before.
  757. * Therefore, this function must be called when OPAMP init
  758. * parameter "UserTrimming" is set to trimming factory,
  759. * and before OPAMP calibration (function
  760. * "HAL_OPAMP_SelfCalibrate()").
  761. * Otherwise, factory trimming value cannot be retrieved and
  762. * error status is returned.
  763. * @param hopamp : OPAMP handle
  764. * @param trimmingoffset : Trimming offset (P or N)
  765. * This parameter must be a value of @ref OPAMP_FactoryTrimming
  766. * @note Calibration parameter retrieved is corresponding to the mode
  767. * specified in OPAMP init structure (mode normal or low-power).
  768. * To retrieve calibration parameters for both modes, repeat this
  769. * function after OPAMP init structure accordingly updated.
  770. * @retval Trimming value (P or N): range: 0->31
  771. * or OPAMP_FACTORYTRIMMING_DUMMY if trimming value is not available
  772. *
  773. */
  774. HAL_OPAMP_TrimmingValueTypeDef HAL_OPAMP_GetTrimOffset (OPAMP_HandleTypeDef *hopamp, uint32_t trimmingoffset)
  775. {
  776. HAL_OPAMP_TrimmingValueTypeDef trimmingvalue;
  777. __IO uint32_t* tmp_opamp_reg_trimming; /* Selection of register of trimming depending on power mode: OTR or LPOTR */
  778. /* Check the OPAMP handle allocation */
  779. /* Value can be retrieved in HAL_OPAMP_STATE_READY state */
  780. if(hopamp == NULL)
  781. {
  782. return OPAMP_FACTORYTRIMMING_DUMMY;
  783. }
  784. /* Check the OPAMP handle allocation */
  785. /* Value can be retrieved in HAL_OPAMP_STATE_READY state */
  786. if(hopamp->State == HAL_OPAMP_STATE_READY)
  787. {
  788. /* Check the parameter */
  789. assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
  790. assert_param(IS_OPAMP_FACTORYTRIMMING(trimmingoffset));
  791. assert_param(IS_OPAMP_POWERMODE(hopamp->Init.PowerMode));
  792. /* Check the trimming mode */
  793. if (READ_BIT(hopamp->Instance->CSR,OPAMP_CSR_USERTRIM) != 0U)
  794. {
  795. /* This function must called when OPAMP init parameter "UserTrimming" */
  796. /* is set to trimming factory, and before OPAMP calibration (function */
  797. /* "HAL_OPAMP_SelfCalibrate()"). */
  798. /* Otherwise, factory trimming value cannot be retrieved and error */
  799. /* status is returned. */
  800. trimmingvalue = OPAMP_FACTORYTRIMMING_DUMMY;
  801. }
  802. else
  803. {
  804. /* Select trimming settings depending on power mode */
  805. if (hopamp->Init.PowerMode == OPAMP_POWERMODE_NORMALPOWER)
  806. {
  807. tmp_opamp_reg_trimming = &OPAMP->OTR;
  808. }
  809. else
  810. {
  811. tmp_opamp_reg_trimming = &OPAMP->LPOTR;
  812. }
  813. /* Get factory trimming */
  814. if (trimmingoffset == OPAMP_FACTORYTRIMMING_P)
  815. {
  816. /* OPAMP_FACTORYTRIMMING_P */
  817. trimmingvalue = ((*tmp_opamp_reg_trimming) & OPAMP_OTR_TRIMOFFSETP) >> OPAMP_INPUT_NONINVERTING;
  818. }
  819. else
  820. {
  821. /* OPAMP_FACTORYTRIMMING_N */
  822. trimmingvalue = (*tmp_opamp_reg_trimming) & OPAMP_OTR_TRIMOFFSETN;
  823. }
  824. }
  825. }
  826. else
  827. {
  828. return OPAMP_FACTORYTRIMMING_DUMMY;
  829. }
  830. return trimmingvalue;
  831. }
  832. /**
  833. * @}
  834. */
  835. /** @defgroup OPAMP_Exported_Functions_Group4 Peripheral State functions
  836. * @brief Peripheral State functions
  837. *
  838. @verbatim
  839. ===============================================================================
  840. ##### Peripheral State functions #####
  841. ===============================================================================
  842. [..]
  843. This subsection permits to get in run-time the status of the peripheral.
  844. @endverbatim
  845. * @{
  846. */
  847. /**
  848. * @brief Return the OPAMP handle state.
  849. * @param hopamp : OPAMP handle
  850. * @retval HAL state
  851. */
  852. HAL_OPAMP_StateTypeDef HAL_OPAMP_GetState(OPAMP_HandleTypeDef *hopamp)
  853. {
  854. /* Check the OPAMP handle allocation */
  855. if(hopamp == NULL)
  856. {
  857. return HAL_OPAMP_STATE_RESET;
  858. }
  859. /* Check the parameter */
  860. assert_param(IS_OPAMP_ALL_INSTANCE(hopamp->Instance));
  861. /* Return OPAMP handle state */
  862. return hopamp->State;
  863. }
  864. /**
  865. * @}
  866. */
  867. #if (USE_HAL_OPAMP_REGISTER_CALLBACKS == 1)
  868. /**
  869. * @brief Register a User OPAMP Callback
  870. * To be used instead of the weak (overridden) predefined callback
  871. * @param hopamp : OPAMP handle
  872. * @param CallbackID : ID of the callback to be registered
  873. * This parameter can be one of the following values:
  874. * @arg @ref HAL_OPAMP_MSPINIT_CB_ID OPAMP MspInit callback ID
  875. * @arg @ref HAL_OPAMP_MSPDEINIT_CB_ID OPAMP MspDeInit callback ID
  876. * @param pCallback : pointer to the Callback function
  877. * @retval status
  878. */
  879. HAL_StatusTypeDef HAL_OPAMP_RegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackID, pOPAMP_CallbackTypeDef pCallback)
  880. {
  881. HAL_StatusTypeDef status = HAL_OK;
  882. if(pCallback == NULL)
  883. {
  884. return HAL_ERROR;
  885. }
  886. /* Process locked */
  887. __HAL_LOCK(hopamp);
  888. if(hopamp->State == HAL_OPAMP_STATE_READY)
  889. {
  890. switch (CallbackID)
  891. {
  892. case HAL_OPAMP_MSPINIT_CB_ID :
  893. hopamp->MspInitCallback = pCallback;
  894. break;
  895. case HAL_OPAMP_MSPDEINIT_CB_ID :
  896. hopamp->MspDeInitCallback = pCallback;
  897. break;
  898. default :
  899. /* update return status */
  900. status = HAL_ERROR;
  901. break;
  902. }
  903. }
  904. else if (hopamp->State == HAL_OPAMP_STATE_RESET)
  905. {
  906. switch (CallbackID)
  907. {
  908. case HAL_OPAMP_MSPINIT_CB_ID :
  909. hopamp->MspInitCallback = pCallback;
  910. break;
  911. case HAL_OPAMP_MSPDEINIT_CB_ID :
  912. hopamp->MspDeInitCallback = pCallback;
  913. break;
  914. default :
  915. /* update return status */
  916. status = HAL_ERROR;
  917. break;
  918. }
  919. }
  920. else
  921. {
  922. /* update return status */
  923. status = HAL_ERROR;
  924. }
  925. /* Release Lock */
  926. __HAL_UNLOCK(hopamp);
  927. return status;
  928. }
  929. /**
  930. * @brief Unregister a User OPAMP Callback
  931. * OPAMP Callback is redirected to the weak (overridden) predefined callback
  932. * @param hopamp : OPAMP handle
  933. * @param CallbackID : ID of the callback to be unregistered
  934. * This parameter can be one of the following values:
  935. * @arg @ref HAL_OPAMP_MSPINIT_CB_ID OPAMP MSP Init Callback ID
  936. * @arg @ref HAL_OPAMP_MSPDEINIT_CB_ID OPAMP MSP DeInit Callback ID
  937. * @arg @ref HAL_OPAMP_ALL_CB_ID OPAMP All Callbacks
  938. * @retval status
  939. */
  940. HAL_StatusTypeDef HAL_OPAMP_UnRegisterCallback (OPAMP_HandleTypeDef *hopamp, HAL_OPAMP_CallbackIDTypeDef CallbackID)
  941. {
  942. HAL_StatusTypeDef status = HAL_OK;
  943. /* Process locked */
  944. __HAL_LOCK(hopamp);
  945. if(hopamp->State == HAL_OPAMP_STATE_READY)
  946. {
  947. switch (CallbackID)
  948. {
  949. case HAL_OPAMP_MSPINIT_CB_ID :
  950. hopamp->MspInitCallback = HAL_OPAMP_MspInit;
  951. break;
  952. case HAL_OPAMP_MSPDEINIT_CB_ID :
  953. hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
  954. break;
  955. case HAL_OPAMP_ALL_CB_ID :
  956. hopamp->MspInitCallback = HAL_OPAMP_MspInit;
  957. hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
  958. break;
  959. default :
  960. /* update return status */
  961. status = HAL_ERROR;
  962. break;
  963. }
  964. }
  965. else if (hopamp->State == HAL_OPAMP_STATE_RESET)
  966. {
  967. switch (CallbackID)
  968. {
  969. case HAL_OPAMP_MSPINIT_CB_ID :
  970. hopamp->MspInitCallback = HAL_OPAMP_MspInit;
  971. break;
  972. case HAL_OPAMP_MSPDEINIT_CB_ID :
  973. hopamp->MspDeInitCallback = HAL_OPAMP_MspDeInit;
  974. break;
  975. default :
  976. /* update return status */
  977. status = HAL_ERROR;
  978. break;
  979. }
  980. }
  981. else
  982. {
  983. /* update return status */
  984. status = HAL_ERROR;
  985. }
  986. /* Release Lock */
  987. __HAL_UNLOCK(hopamp);
  988. return status;
  989. }
  990. #endif /* USE_HAL_OPAMP_REGISTER_CALLBACKS */
  991. /**
  992. * @}
  993. */
  994. /**
  995. * @}
  996. */
  997. #endif /* HAL_OPAMP_MODULE_ENABLED */
  998. /**
  999. * @}
  1000. */
  1001. /**
  1002. * @}
  1003. */