You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

826 lines
36 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_ll_opamp.h
  4. * @author MCD Application Team
  5. * @brief Header file of OPAMP LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef __STM32H7xx_LL_OPAMP_H
  21. #define __STM32H7xx_LL_OPAMP_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32h7xx.h"
  27. /** @addtogroup STM32H7xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (OPAMP1) || defined (OPAMP2)
  31. /** @defgroup OPAMP_LL OPAMP
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /** @defgroup OPAMP_LL_Private_Constants OPAMP Private Constants
  38. * @{
  39. */
  40. /* Internal mask for OPAMP power mode: */
  41. /* To select into literal LL_OPAMP_POWERMODE_x the relevant bits for: */
  42. /* - OPAMP power mode into control register */
  43. /* - OPAMP trimming register offset */
  44. /* Internal register offset for OPAMP trimming configuration */
  45. #define OPAMP_POWERMODE_OTR_REGOFFSET 0x00000000U
  46. #define OPAMP_POWERMODE_HSOTR_REGOFFSET 0x00000001U
  47. #define OPAMP_POWERMODE_OTR_REGOFFSET_MASK (OPAMP_POWERMODE_OTR_REGOFFSET | OPAMP_POWERMODE_HSOTR_REGOFFSET)
  48. /* Mask for OPAMP power mode into control register */
  49. #define OPAMP_POWERMODE_CSR_BIT_MASK (OPAMP_CSR_OPAHSM)
  50. /* Internal mask for OPAMP trimming of transistors differential pair NMOS */
  51. /* or PMOS. */
  52. /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for: */
  53. /* - OPAMP trimming selection of transistors differential pair */
  54. /* - OPAMP trimming values of transistors differential pair */
  55. #define OPAMP_TRIMMING_SELECT_MASK 0x00030000U
  56. #define OPAMP_TRIMMING_VALUE_MASK (OPAMP_OTR_TRIMOFFSETP | OPAMP_OTR_TRIMOFFSETN)
  57. /**
  58. * @}
  59. */
  60. /* Private macros ------------------------------------------------------------*/
  61. /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
  62. * @{
  63. */
  64. /**
  65. * @brief Driver macro reserved for internal use: set a pointer to
  66. * a register from a register basis from which an offset
  67. * is applied.
  68. * @param __REG__ Register basis from which the offset is applied.
  69. * @param __REG_OFFSET__ Offset to be applied (unit: number of registers).
  70. * @retval Register address
  71. */
  72. #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__) \
  73. ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U))))
  74. /**
  75. * @}
  76. */
  77. /* Exported types ------------------------------------------------------------*/
  78. #if defined(USE_FULL_LL_DRIVER)
  79. /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure
  80. * @{
  81. */
  82. /**
  83. * @brief Structure definition of some features of OPAMP instance.
  84. */
  85. typedef struct
  86. {
  87. uint32_t PowerMode; /*!< Set OPAMP power mode.
  88. This parameter can be a value of @ref OPAMP_LL_EC_POWER_MODE
  89. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */
  90. uint32_t FunctionalMode; /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
  91. This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
  92. @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain().
  93. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
  94. uint32_t InputNonInverting; /*!< Set OPAMP input non-inverting connection.
  95. This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
  96. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
  97. uint32_t InputInverting; /*!< Set OPAMP inverting input connection.
  98. This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
  99. @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with external capacitors for filtering circuit. Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin), this parameter is discarded.
  100. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
  101. } LL_OPAMP_InitTypeDef;
  102. /**
  103. * @}
  104. */
  105. #endif /* USE_FULL_LL_DRIVER */
  106. /* Exported constants --------------------------------------------------------*/
  107. /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
  108. * @{
  109. */
  110. /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
  111. * @{
  112. */
  113. #define LL_OPAMP_MODE_FUNCTIONAL 0x00000000U /*!< OPAMP functional mode */
  114. #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_CALON) /*!< OPAMP calibration mode */
  115. /**
  116. * @}
  117. */
  118. /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
  119. * @{
  120. */
  121. #define LL_OPAMP_MODE_STANDALONE 0x00000000U /*!< OPAMP functional mode, OPAMP operation in standalone */
  122. #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0) /*!< OPAMP functional mode, OPAMP operation in follower */
  123. #define LL_OPAMP_MODE_PGA (OPAMP_CSR_VMSEL_1) /*!< OPAMP functional mode, OPAMP operation in PGA */
  124. #define LL_OPAMP_MODE_PGA_IO0 (OPAMP_CSR_PGGAIN_2|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0 for filtering */
  125. #define LL_OPAMP_MODE_PGA_IO0_BIAS (OPAMP_CSR_PGGAIN_3|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0
  126. - Input signal on VINM0, bias on VINPx: negative gain
  127. - Bias on VINM0, input signal on VINPx: positive gain */
  128. #define LL_OPAMP_MODE_PGA_IO0_IO1_BIAS (OPAMP_CSR_PGGAIN_3|OPAMP_CSR_PGGAIN_2|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0
  129. - Input signal on VINM0, bias on VINPx: negative gain
  130. - Bias on VINM0, input signal on VINPx: positive gain
  131. And VINM1 is connected too for filtering */
  132. /**
  133. * @}
  134. */
  135. /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
  136. * @note Gain sign:
  137. * - is positive if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is
  138. * @ref LL_OPAMP_MODE_PGA or LL_OPAMP_MODE_PGA_IO0
  139. * - may be positive or negative if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is
  140. * @ref LL_OPAMP_MODE_PGA_IO0_BIAS or LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
  141. * see @ref OPAMP_LL_EC_FUNCTIONAL_MODE for more details
  142. * @{
  143. */
  144. #define LL_OPAMP_PGA_GAIN_2_OR_MINUS_1 0x00000000U /*!< OPAMP PGA gain 2 or -1 */
  145. #define LL_OPAMP_PGA_GAIN_4_OR_MINUS_3 ( OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 4 or -3 */
  146. #define LL_OPAMP_PGA_GAIN_8_OR_MINUS_7 ( OPAMP_CSR_PGGAIN_1 ) /*!< OPAMP PGA gain 8 or -7 */
  147. #define LL_OPAMP_PGA_GAIN_16_OR_MINUS_15 ( OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 16 or -15 */
  148. /**
  149. * @}
  150. */
  151. /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
  152. * @{
  153. */
  154. #define LL_OPAMP_INPUT_NONINVERT_IO0 0x00000000U /*!< OPAMP non inverting input connected to I/O VINP0
  155. (PB0 for OPAMP1, PE9 for OPAMP2)
  156. Note: On this STM32 serie, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  157. #define LL_OPAMP_INPUT_NONINVERT_DAC OPAMP_CSR_VPSEL_0 /*!< OPAMP non inverting input connected internally to DAC channel
  158. (DAC1_CH1 for OPAMP1, DAC1_CH2 for OPAMP2)
  159. Note: On this STM32 serie, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  160. #if defined(DAC2)
  161. #define LL_OPAMP_INPUT_NONINVERT_DAC2 OPAMP_CSR_VPSEL_1 /*!< OPAMP non inverting input connected internally to DAC2 channel
  162. (DAC3 only for OPAMP2)*/
  163. #endif /* DAC2 */
  164. /**
  165. * @}
  166. */
  167. /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
  168. * @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with negative gain or bias.
  169. * Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin).
  170. * @{
  171. */
  172. #define LL_OPAMP_INPUT_INVERT_IO0 0x00000000U /*!< OPAMP inverting input connected to I/O VINM0
  173. (PC5 for OPAMP1, PE8 for OPAMP2)
  174. Note: On this STM32 serie, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  175. #define LL_OPAMP_INPUT_INVERT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to I/0 VINM1
  176. (PA7 for OPAMP1, PG1 for OPAMP2)
  177. Note: On this STM32 serie, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  178. #define LL_OPAMP_INPUT_INVERT_CONNECT_NO OPAMP_CSR_VMSEL_1 /*!< OPAMP inverting input not externally connected (intended for OPAMP in mode follower or PGA with positive gain without bias).
  179. Note: On this STM32 serie, this literal include cases of value 0x11 for mode follower and value 0x10 for mode PGA. */
  180. /**
  181. * @}
  182. */
  183. /** @defgroup OPAMP_LL_EC_POWER_MODE OPAMP PowerMode
  184. * @{
  185. */
  186. #define LL_OPAMP_POWERMODE_NORMAL (OPAMP_POWERMODE_OTR_REGOFFSET) /*!< OPAMP output in normal mode */
  187. #define LL_OPAMP_POWERMODE_HIGHSPEED (OPAMP_POWERMODE_HSOTR_REGOFFSET | OPAMP_CSR_OPAHSM) /*!< OPAMP output in highspeed mode */
  188. /**
  189. * @}
  190. */
  191. /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
  192. * @{
  193. */
  194. #define LL_OPAMP_TRIMMING_FACTORY 0x00000000U /*!< OPAMP trimming factors set to factory values */
  195. #define LL_OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< OPAMP trimming factors set to user values */
  196. /**
  197. * @}
  198. */
  199. /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
  200. * @{
  201. */
  202. #define LL_OPAMP_TRIMMING_NMOS_VREF_90PC_VDDA (OPAMP_OTR_TRIMOFFSETN | ((OPAMP_CSR_CALSEL_1 | OPAMP_CSR_CALSEL_0) << 4)) /*!< OPAMP trimming of transistors differential pair NMOS (internal reference voltage set to 0.9*Vdda). Default parameters to be used for calibration using two trimming steps (one with each transistors differential pair NMOS and PMOS). */
  203. #define LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA (OPAMP_OTR_TRIMOFFSETN | (OPAMP_CSR_CALSEL_1 << 4)) /*!< OPAMP trimming of transistors differential pair NMOS (internal reference voltage set to 0.5*Vdda). */
  204. #define LL_OPAMP_TRIMMING_PMOS_VREF_10PC_VDDA (OPAMP_OTR_TRIMOFFSETP | (OPAMP_CSR_CALSEL_0 << 4)) /*!< OPAMP trimming of transistors differential pair PMOS (internal reference voltage set to 0.1*Vdda). Default parameters to be used for calibration using two trimming steps (one with each transistors differential pair NMOS and PMOS). */
  205. #define LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA (OPAMP_OTR_TRIMOFFSETP ) /*!< OPAMP trimming of transistors differential pair PMOS (internal reference voltage set to 0.33*Vdda). */
  206. #define LL_OPAMP_TRIMMING_NMOS (LL_OPAMP_TRIMMING_NMOS_VREF_90PC_VDDA) /*!< OPAMP trimming of transistors differential pair NMOS (internal reference voltage set to 0.9*Vdda). Default parameters to be used for calibration using two trimming steps (one with each transistors differential pair NMOS and PMOS). */
  207. #define LL_OPAMP_TRIMMING_PMOS (LL_OPAMP_TRIMMING_PMOS_VREF_10PC_VDDA) /*!< OPAMP trimming of transistors differential pair PMOS (internal reference voltage set to 0.1*Vdda). Default parameters to be used for calibration using two trimming steps (one with each transistors differential pair NMOS and PMOS). */
  208. /**
  209. * @}
  210. */
  211. /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays
  212. * @note Only OPAMP IP HW delays are defined in OPAMP LL driver driver,
  213. * not timeout values.
  214. * For details on delays values, refer to descriptions in source code
  215. * above each literal definition.
  216. * @{
  217. */
  218. /* Delay for OPAMP startup time (transition from state disable to enable). */
  219. /* Note: OPAMP startup time depends on board application environment: */
  220. /* impedance connected to OPAMP output. */
  221. /* The delay below is specified under conditions: */
  222. /* - OPAMP in functional mode follower */
  223. /* - load impedance of 4kOhm (min), 50pF (max) */
  224. /* Literal set to maximum value (refer to device datasheet, */
  225. /* parameter "tWAKEUP"). */
  226. /* Unit: us */
  227. #define LL_OPAMP_DELAY_STARTUP_US (3U) /*!< Delay for OPAMP startup time */
  228. /**
  229. * @}
  230. */
  231. /**
  232. * @}
  233. */
  234. /* Exported macro ------------------------------------------------------------*/
  235. /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
  236. * @{
  237. */
  238. /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
  239. * @{
  240. */
  241. /**
  242. * @brief Write a value in OPAMP LL_OPAMP_GetPowerModeregister
  243. * @param __INSTANCE__ OPAMP Instance
  244. * @param __REG__ Register to be written
  245. * @param __VALUE__ Value to be written in the register
  246. * @retval None
  247. */
  248. #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  249. /**
  250. * @brief Read a value in OPAMP register
  251. * @param __INSTANCE__ OPAMP Instance
  252. * @param __REG__ Register to be read
  253. * @retval Register value
  254. */
  255. #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  256. /**
  257. * @}
  258. */
  259. /** @defgroup OPAMP_LL_EM_HELPER_MACRO OPAMP helper macro
  260. * @{
  261. */
  262. /**
  263. * @brief Helper macro to select the OPAMP common instance
  264. * to which is belonging the selected OPAMP instance.
  265. * @note OPAMP common register instance can be used to
  266. * set parameters common to several OPAMP instances.
  267. * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
  268. * @param __OPAMPx__ OPAMP instance
  269. * @retval OPAMP common instance
  270. */
  271. #if defined(OPAMP1) && defined(OPAMP2)
  272. #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \
  273. (OPAMP12_COMMON)
  274. #endif
  275. /**
  276. * @brief Helper macro to check if all OPAMP instances sharing the same
  277. * OPAMP common instance are disabled.
  278. * @note This check is required by functions with setting conditioned to
  279. * OPAMP state:
  280. * All OPAMP instances of the OPAMP common group must be disabled.
  281. * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
  282. * @retval 0: All OPAMP instances sharing the same OPAMP common instance
  283. * are disabled.
  284. * 1: At least one OPAMP instance sharing the same OPAMP common instance
  285. * is enabled
  286. */
  287. #if defined(OPAMP1) && defined(OPAMP2)
  288. #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \
  289. (LL_OPAMP_IsEnabled(OPAMP1) | \
  290. LL_OPAMP_IsEnabled(OPAMP2) )
  291. #endif
  292. /**
  293. * @}
  294. */
  295. /**
  296. * @}
  297. */
  298. /* Exported functions --------------------------------------------------------*/
  299. /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
  300. * @{
  301. */
  302. /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
  303. * @{
  304. */
  305. /**
  306. * @brief Set OPAMP mode calibration or functional.
  307. * @note OPAMP mode corresponds to functional or calibration mode:
  308. * - functional mode: OPAMP operation in standalone, follower, ...
  309. * Set functional mode using function
  310. * @ref LL_OPAMP_SetFunctionalMode().
  311. * - calibration mode: offset calibration of the selected
  312. * transistors differential pair NMOS or PMOS.
  313. * @rmtoll CSR CALON LL_OPAMP_SetMode
  314. * @param OPAMPx OPAMP instance
  315. * @param Mode This parameter can be one of the following values:
  316. * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  317. * @arg @ref LL_OPAMP_MODE_CALIBRATION
  318. * @retval None
  319. */
  320. __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
  321. {
  322. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
  323. }
  324. /**
  325. * @brief Get OPAMP mode calibration or functional.
  326. * @note OPAMP mode corresponds to functional or calibration mode:
  327. * - functional mode: OPAMP operation in standalone, follower, ...
  328. * Set functional mode using function
  329. * @ref LL_OPAMP_SetFunctionalMode().
  330. * - calibration mode: offset calibration of the selected
  331. * transistors differential pair NMOS or PMOS.
  332. * @rmtoll CSR CALON LL_OPAMP_GetMode
  333. * @param OPAMPx OPAMP instance
  334. * @retval Returned value can be one of the following values:
  335. * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  336. * @arg @ref LL_OPAMP_MODE_CALIBRATION
  337. */
  338. __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
  339. {
  340. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
  341. }
  342. /**
  343. * @brief Set OPAMP functional mode by setting internal connections.
  344. * OPAMP operation in standalone, follower, ...
  345. * @note This function reset bit of calibration mode to ensure
  346. * to be in functional mode, in order to have OPAMP parameters
  347. * (inputs selection, ...) set with the corresponding OPAMP mode
  348. * to be effective.
  349. * @rmtoll CSR VMSEL LL_OPAMP_SetFunctionalMode
  350. * @param OPAMPx OPAMP instance
  351. * @param FunctionalMode This parameter can be one of the following values:
  352. * @arg @ref LL_OPAMP_MODE_STANDALONE
  353. * @arg @ref LL_OPAMP_MODE_FOLLOWER
  354. * @arg @ref LL_OPAMP_MODE_PGA
  355. * @arg @ref LL_OPAMP_MODE_PGA_IO0
  356. * @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS
  357. * @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
  358. * @retval None
  359. */
  360. __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
  361. {
  362. /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
  363. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL | OPAMP_CSR_CALON, FunctionalMode);
  364. }
  365. /**
  366. * @brief Get OPAMP functional mode from setting of internal connections.
  367. * OPAMP operation in standalone, follower, ...
  368. * @rmtoll CSR VMSEL LL_OPAMP_GetFunctionalMode
  369. * @param OPAMPx OPAMP instance
  370. * @retval Returned value can be one of the following values:
  371. * @arg @ref LL_OPAMP_MODE_STANDALONE
  372. * @arg @ref LL_OPAMP_MODE_FOLLOWER
  373. * @arg @ref LL_OPAMP_MODE_PGA
  374. * @arg @ref LL_OPAMP_MODE_PGA_IO0
  375. * @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS
  376. * @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
  377. */
  378. __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
  379. {
  380. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL));
  381. }
  382. /**
  383. * @brief Set OPAMP PGA gain.
  384. * @note Preliminarily, OPAMP must be set in mode PGA
  385. * using function @ref LL_OPAMP_SetFunctionalMode().
  386. * @rmtoll CSR PGGAIN LL_OPAMP_SetPGAGain
  387. * @param OPAMPx OPAMP instance
  388. * @param PGAGain This parameter can be one of the following values:
  389. * @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1
  390. * @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3
  391. * @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7
  392. * @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15
  393. * @retval None
  394. */
  395. __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
  396. {
  397. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0, PGAGain);
  398. }
  399. /**
  400. * @brief Get OPAMP PGA gain.
  401. * @note Preliminarily, OPAMP must be set in mode PGA
  402. * using function @ref LL_OPAMP_SetFunctionalMode().
  403. * @rmtoll CSR PGGAIN LL_OPAMP_GetPGAGain
  404. * @param OPAMPx OPAMP instance
  405. * @retval Returned value can be one of the following values:
  406. * @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1
  407. * @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3
  408. * @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7
  409. * @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15
  410. */
  411. __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx)
  412. {
  413. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0));
  414. }
  415. /**
  416. * @brief Set OPAMP power mode normal or highspeed.
  417. * @note OPAMP highspeed mode allows output stage to have a better slew rate.
  418. * @rmtoll CSR OPAHSM LL_OPAMP_SetPowerMode
  419. * @param OPAMPx OPAMP instance
  420. * @param PowerMode This parameter can be one of the following values:
  421. * @arg @ref LL_OPAMP_POWERMODE_NORMAL
  422. * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
  423. * @retval None
  424. */
  425. __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
  426. {
  427. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAHSM, (PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK));
  428. }
  429. /**
  430. * @brief Get OPAMP power mode normal or highspeed.
  431. * @note OPAMP highspeed mode allows output stage to have a better slew rate.
  432. * @rmtoll CSR OPAHSM LL_OPAMP_GetPowerMode
  433. * @param OPAMPx OPAMP instance
  434. * @retval Returned value can be one of the following values:
  435. * @arg @ref LL_OPAMP_POWERMODE_NORMAL
  436. * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
  437. */
  438. __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx)
  439. {
  440. register uint32_t power_mode = (READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAHSM));
  441. return (uint32_t)(power_mode | (power_mode >> (OPAMP_CSR_OPAHSM_Pos)));
  442. }
  443. /**
  444. * @}
  445. */
  446. /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
  447. * @{
  448. */
  449. /**
  450. * @brief Set OPAMP non-inverting input connection.
  451. * @rmtoll CSR VPSEL LL_OPAMP_SetInputNonInverting
  452. * @param OPAMPx OPAMP instance
  453. * @param InputNonInverting This parameter can be one of the following values:
  454. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  455. * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC
  456. * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC2 (Only for OPAMP2)
  457. * @retval None
  458. */
  459. __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
  460. {
  461. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting);
  462. }
  463. /**
  464. * @brief Get OPAMP non-inverting input connection.
  465. * @rmtoll CSR VPSEL LL_OPAMP_GetInputNonInverting
  466. * @param OPAMPx OPAMP instance
  467. * @retval Returned value can be one of the following values:
  468. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  469. * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC
  470. * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC2 (Only for OPAMP2)
  471. */
  472. __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
  473. {
  474. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL));
  475. }
  476. /**
  477. * @brief Set OPAMP inverting input connection.
  478. * @note OPAMP inverting input is used with OPAMP in mode standalone
  479. * or PGA with external capacitors for filtering circuit.
  480. * Otherwise (OPAMP in mode follower), OPAMP inverting input
  481. * is not used (not connected to GPIO pin).
  482. * @rmtoll CSR VMSEL LL_OPAMP_SetInputInverting
  483. * @param OPAMPx OPAMP instance
  484. * @param InputInverting This parameter can be one of the following values:
  485. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  486. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
  487. * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  488. * @retval None
  489. */
  490. __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
  491. {
  492. /* Manage cases of OPAMP inverting input not connected (0x10 and 0x11) */
  493. /* to not modify OPAMP mode follower or PGA. */
  494. /* Bit OPAMP_CSR_VMSEL_1 is set by OPAMP mode (follower, PGA). */
  495. MODIFY_REG(OPAMPx->CSR, (~(InputInverting >> 1)) & OPAMP_CSR_VMSEL_0, InputInverting);
  496. }
  497. /**
  498. * @brief Get OPAMP inverting input connection.
  499. * @rmtoll CSR VMSEL LL_OPAMP_GetInputInverting
  500. * @param OPAMPx OPAMP instance
  501. * @retval Returned value can be one of the following values:
  502. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  503. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
  504. * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  505. */
  506. __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
  507. {
  508. register uint32_t input_inverting = READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL);
  509. /* Manage cases 0x10 and 0x11 to return the same value: OPAMP inverting */
  510. /* input not connected. */
  511. return (input_inverting & ~((input_inverting >> 1) & OPAMP_CSR_VMSEL_0));
  512. }
  513. /**
  514. * @}
  515. */
  516. /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
  517. * @{
  518. */
  519. /**
  520. * @brief Set OPAMP trimming mode.
  521. * @rmtoll CSR USERTRIM LL_OPAMP_SetTrimmingMode
  522. * @param OPAMPx OPAMP instance
  523. * @param TrimmingMode This parameter can be one of the following values:
  524. * @arg @ref LL_OPAMP_TRIMMING_FACTORY
  525. * @arg @ref LL_OPAMP_TRIMMING_USER
  526. * @retval None
  527. */
  528. __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode)
  529. {
  530. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode);
  531. }
  532. /**
  533. * @brief Get OPAMP trimming mode.
  534. * @rmtoll CSR USERTRIM LL_OPAMP_GetTrimmingMode
  535. * @param OPAMPx OPAMP instance
  536. * @retval Returned value can be one of the following values:
  537. * @arg @ref LL_OPAMP_TRIMMING_FACTORY
  538. * @arg @ref LL_OPAMP_TRIMMING_USER
  539. */
  540. __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx)
  541. {
  542. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM));
  543. }
  544. /**
  545. * @brief Set OPAMP offset to calibrate the selected transistors
  546. * differential pair NMOS or PMOS.
  547. * @note Preliminarily, OPAMP must be set in mode calibration
  548. * using function @ref LL_OPAMP_SetMode().
  549. * @rmtoll CSR CALSEL LL_OPAMP_SetCalibrationSelection
  550. * @param OPAMPx OPAMP instance
  551. * @param TransistorsDiffPair This parameter can be one of the following values:
  552. * @arg @ref LL_OPAMP_TRIMMING_NMOS (1)
  553. * @arg @ref LL_OPAMP_TRIMMING_PMOS (1)
  554. * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
  555. * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
  556. *
  557. * (1) Default parameters to be used for calibration
  558. * using two trimming steps (one with each transistors differential
  559. * pair NMOS and PMOS)
  560. * @retval None
  561. */
  562. __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
  563. {
  564. /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */
  565. /* containing other bits reserved for other purpose. */
  566. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, ((TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK) >> 4));
  567. }
  568. /**
  569. * @brief Get OPAMP offset to calibrate the selected transistors
  570. * differential pair NMOS or PMOS.
  571. * @note Preliminarily, OPAMP must be set in mode calibration
  572. * using function @ref LL_OPAMP_SetMode().
  573. * @rmtoll CSR CALSEL LL_OPAMP_GetCalibrationSelection
  574. * @param OPAMPx OPAMP instance
  575. * @retval Returned value can be one of the following values:
  576. * @arg @ref LL_OPAMP_TRIMMING_NMOS (1)
  577. * @arg @ref LL_OPAMP_TRIMMING_PMOS (1)
  578. * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
  579. * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
  580. *
  581. * (1) Default parameters to be used for calibration
  582. * using two trimming steps (one with each transistors differential
  583. * pair NMOS and PMOS)
  584. */
  585. __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
  586. {
  587. register uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
  588. return (uint32_t)((CalibrationSelection << 4)|
  589. (((CalibrationSelection & OPAMP_CSR_CALSEL_1) == 0UL) ? OPAMP_OTR_TRIMOFFSETN : OPAMP_OTR_TRIMOFFSETP));
  590. }
  591. /**
  592. * @brief Get OPAMP calibration result of toggling output.
  593. * @note This functions returns:
  594. * 0 if OPAMP calibration output is reset
  595. * 1 if OPAMP calibration output is set
  596. * @rmtoll CSR OUTCAL LL_OPAMP_IsCalibrationOutputSet
  597. * @param OPAMPx OPAMP instance
  598. * @retval State of bit (1 or 0).
  599. */
  600. __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
  601. {
  602. return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALOUT) == OPAMP_CSR_CALOUT)?1UL:0UL);
  603. }
  604. /**
  605. * @brief Set OPAMP trimming factor for the selected transistors
  606. * differential pair NMOS or PMOS, corresponding to the selected
  607. * power mode.
  608. * @rmtoll OTR TRIMOFFSETN LL_OPAMP_SetTrimmingValue\n
  609. * OTR TRIMOFFSETP LL_OPAMP_SetTrimmingValue\n
  610. * HSOTR TRIMHSOFFSETN LL_OPAMP_SetTrimmingValue\n
  611. * HSOTR TRIMHSOFFSETP LL_OPAMP_SetTrimmingValue
  612. * @param OPAMPx OPAMP instance
  613. * @param PowerMode This parameter can be one of the following values:
  614. * @arg @ref LL_OPAMP_POWERMODE_NORMAL
  615. * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
  616. * @param TransistorsDiffPair This parameter can be one of the following values:
  617. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  618. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  619. * @param TrimmingValue 0x00...0x1F
  620. * @retval None
  621. */
  622. __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair, uint32_t TrimmingValue)
  623. {
  624. register __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
  625. /* Set bits with position in register depending on parameter */
  626. /* "TransistorsDiffPair". */
  627. /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
  628. /* containing other bits reserved for other purpose. */
  629. MODIFY_REG(*preg,
  630. (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK) << 1U,
  631. TrimmingValue << ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos));
  632. }
  633. /**
  634. * @brief Get OPAMP trimming factor for the selected transistors
  635. * differential pair NMOS or PMOS, corresponding to the selected
  636. * power mode.
  637. * @rmtoll OTR TRIMOFFSETN LL_OPAMP_GetTrimmingValue\n
  638. * OTR TRIMOFFSETP LL_OPAMP_GetTrimmingValue\n
  639. * HSOTR TRIMHSOFFSETN LL_OPAMP_GetTrimmingValue\n
  640. * HSOTR TRIMHSOFFSETP LL_OPAMP_GetTrimmingValue
  641. * @param OPAMPx OPAMP instance
  642. * @param PowerMode This parameter can be one of the following values:
  643. * @arg @ref LL_OPAMP_POWERMODE_NORMAL
  644. * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
  645. * @param TransistorsDiffPair This parameter can be one of the following values:
  646. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  647. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  648. * @retval 0x0...0x1F
  649. */
  650. __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair)
  651. {
  652. register const __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
  653. /* Retrieve bits with position in register depending on parameter */
  654. /* "TransistorsDiffPair". */
  655. /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
  656. /* containing other bits reserved for other purpose. */
  657. return (uint32_t)(READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
  658. >> ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos));
  659. }
  660. /**
  661. * @}
  662. */
  663. /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
  664. * @{
  665. */
  666. /**
  667. * @brief Enable OPAMP instance.
  668. * @note After enable from off state, OPAMP requires a delay
  669. * to fullfill wake up time specification.
  670. * Refer to device datasheet, parameter "tWAKEUP".
  671. * @rmtoll CSR OPAMPXEN LL_OPAMP_Enable
  672. * @param OPAMPx OPAMP instance
  673. * @retval None
  674. */
  675. __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
  676. {
  677. SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
  678. }
  679. /**
  680. * @brief Disable OPAMP instance.
  681. * @rmtoll CSR OPAMPXEN LL_OPAMP_Disable
  682. * @param OPAMPx OPAMP instance
  683. * @retval None
  684. */
  685. __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
  686. {
  687. CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
  688. }
  689. /**
  690. * @brief Get OPAMP instance enable state
  691. * (0: OPAMP is disabled, 1: OPAMP is enabled)
  692. * @rmtoll CSR OPAMPXEN LL_OPAMP_IsEnabled
  693. * @param OPAMPx OPAMP instance
  694. * @retval State of bit (1 or 0).
  695. */
  696. __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx)
  697. {
  698. return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN))?1UL:0UL);
  699. }
  700. /**
  701. * @}
  702. */
  703. #if defined(USE_FULL_LL_DRIVER)
  704. /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
  705. * @{
  706. */
  707. ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
  708. ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  709. void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  710. /**
  711. * @}
  712. */
  713. #endif /* USE_FULL_LL_DRIVER */
  714. /**
  715. * @}
  716. */
  717. /**
  718. * @}
  719. */
  720. #endif /* OPAMP1 || OPAMP2 */
  721. /**
  722. * @}
  723. */
  724. #ifdef __cplusplus
  725. }
  726. #endif
  727. #endif /* __STM32H7xx_LL_OPAMP_H */
  728. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/