stm32g4xx_ll_opamp.h 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_ll_opamp.h
  4. * @author MCD Application Team
  5. * @brief Header file of OPAMP LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2019 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32G4xx_LL_OPAMP_H
  20. #define STM32G4xx_LL_OPAMP_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32g4xx.h"
  26. /** @addtogroup STM32G4xx_LL_Driver
  27. * @{
  28. */
  29. #if defined (OPAMP1) || defined (OPAMP2) || defined (OPAMP3) || defined (OPAMP4) || defined (OPAMP5) || defined (OPAMP6)
  30. /** @defgroup OPAMP_LL OPAMP
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. /** @defgroup OPAMP_LL_Private_Constants OPAMP Private Constants
  37. * @{
  38. */
  39. /* Internal mask for OPAMP trimming of transistors differential pair NMOS */
  40. /* or PMOS. */
  41. /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for: */
  42. /* - OPAMP trimming selection of transistors differential pair */
  43. /* - OPAMP trimming values of transistors differential pair */
  44. #define OPAMP_TRIMMING_SELECT_MASK (OPAMP_CSR_CALSEL)
  45. #define OPAMP_TRIMMING_VALUE_MASK (OPAMP_CSR_TRIMOFFSETN | OPAMP_CSR_TRIMOFFSETP)
  46. /**
  47. * @}
  48. */
  49. /* Private macros ------------------------------------------------------------*/
  50. /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
  51. * @{
  52. */
  53. /**
  54. * @brief Driver macro reserved for internal use: set a pointer to
  55. * a register from a register basis from which an offset
  56. * is applied.
  57. * @param __REG__ Register basis from which the offset is applied.
  58. * @param __REG_OFFSET__ Offset to be applied (unit: number of registers).
  59. * @retval Register address
  60. */
  61. #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__) \
  62. ((__IO uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2))))
  63. /**
  64. * @}
  65. */
  66. /* Exported types ------------------------------------------------------------*/
  67. #if defined(USE_FULL_LL_DRIVER)
  68. /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure
  69. * @{
  70. */
  71. /**
  72. * @brief Structure definition of some features of OPAMP instance.
  73. */
  74. typedef struct
  75. {
  76. uint32_t PowerMode; /*!< Set OPAMP power mode.
  77. This parameter can be a value of @ref OPAMP_LL_EC_POWERMODE
  78. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */
  79. uint32_t FunctionalMode; /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
  80. This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
  81. @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain().
  82. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
  83. uint32_t InputNonInverting; /*!< Set OPAMP input non-inverting connection.
  84. This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
  85. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
  86. uint32_t InputInverting; /*!< Set OPAMP inverting input connection.
  87. This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
  88. @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.
  89. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
  90. } LL_OPAMP_InitTypeDef;
  91. /**
  92. * @}
  93. */
  94. #endif /* USE_FULL_LL_DRIVER */
  95. /* Exported constants --------------------------------------------------------*/
  96. /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
  97. * @{
  98. */
  99. /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
  100. * @{
  101. */
  102. #define LL_OPAMP_MODE_FUNCTIONAL (0x00000000UL) /*!< OPAMP functional mode */
  103. #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_CALON) /*!< OPAMP calibration mode */
  104. /**
  105. * @}
  106. */
  107. /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
  108. * @{
  109. */
  110. #define LL_OPAMP_MODE_STANDALONE (0x00000000UL) /*!< OPAMP functional mode, OPAMP operation in standalone */
  111. #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0) /*!< OPAMP functional mode, OPAMP operation in follower */
  112. #define LL_OPAMP_MODE_PGA (OPAMP_CSR_VMSEL_1) /*!< OPAMP functional mode, OPAMP operation in PGA */
  113. #define LL_OPAMP_MODE_PGA_IO0 (OPAMP_CSR_PGGAIN_4|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0 for filtering */
  114. #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
  115. - Input signal on VINM0, bias on VINPx: negative gain
  116. - Bias on VINM0, input signal on VINPx: positive gain */
  117. #define LL_OPAMP_MODE_PGA_IO0_IO1_BIAS (OPAMP_CSR_PGGAIN_4|OPAMP_CSR_PGGAIN_3|OPAMP_CSR_VMSEL_1) /*!< In PGA mode, the inverting input is connected to VINM0
  118. - Input signal on VINM0, bias on VINPx: negative gain
  119. - Bias on VINM0, input signal on VINPx: positive gain
  120. And VINM1 is connected too for filtering */
  121. /**
  122. * @}
  123. */
  124. /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
  125. * @note Gain sign:
  126. * - is positive if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is
  127. * @ref LL_OPAMP_MODE_PGA or LL_OPAMP_MODE_PGA_IO0
  128. * - may be positive or negative if the @ref OPAMP_LL_EC_FUNCTIONAL_MODE configuration is
  129. * @ref LL_OPAMP_MODE_PGA_IO0_BIAS or LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
  130. * see @ref OPAMP_LL_EC_FUNCTIONAL_MODE for more details
  131. * @{
  132. */
  133. #define LL_OPAMP_PGA_GAIN_2_OR_MINUS_1 (0x00000000UL) /*!< OPAMP PGA gain 2 or -1 */
  134. #define LL_OPAMP_PGA_GAIN_4_OR_MINUS_3 ( OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 4 or -3 */
  135. #define LL_OPAMP_PGA_GAIN_8_OR_MINUS_7 ( OPAMP_CSR_PGGAIN_1 ) /*!< OPAMP PGA gain 8 or -7 */
  136. #define LL_OPAMP_PGA_GAIN_16_OR_MINUS_15 ( OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 16 or -15 */
  137. #define LL_OPAMP_PGA_GAIN_32_OR_MINUS_31 (OPAMP_CSR_PGGAIN_2 ) /*!< OPAMP PGA gain 32 or -31 */
  138. #define LL_OPAMP_PGA_GAIN_64_OR_MINUS_63 (OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 64 or -63 */
  139. /**
  140. * @}
  141. */
  142. /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
  143. * @{
  144. */
  145. #define LL_OPAMP_INPUT_NONINVERT_IO0 (0x00000000UL) /*!< OPAMP non inverting input connected to I/O VINP0
  146. (PA1 for OPAMP1, PA7 for OPAMP2, PB0 for OPAMP3, PB13 for OPAMP4, PB14 for OPAMP5, PB12 for OPAMP6)
  147. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  148. #define LL_OPAMP_INPUT_NONINVERT_IO1 OPAMP_CSR_VPSEL_0 /*!< OPAMP non inverting input connected to I/O VINP1
  149. (PA3 for OPAMP1, PB14 for OPAMP2, PB13 for OPAMP3, PD11 for OPAMP4, PD12 for OPAMP5, PD9 for OPAMP6)
  150. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  151. #define LL_OPAMP_INPUT_NONINVERT_IO2 OPAMP_CSR_VPSEL_1 /*!< OPAMP non inverting input connected to I/O VINP2
  152. (PA7 for OPAMP1, PB0 for OPAMP2, PA1 for OPAMP3, PB11 for OPAMP4, PC3 for OPAMP5, PB13 for OPAMP6)
  153. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  154. #define LL_OPAMP_INPUT_NONINVERT_IO3 OPAMP_CSR_VPSEL /*!< OPAMP non inverting input connected to I/O VINP3
  155. (PD14 for OPAMP2) */
  156. #define LL_OPAMP_INPUT_NONINVERT_DAC OPAMP_CSR_VPSEL /*!< OPAMP non inverting input connected internally to DAC channel
  157. (DAC3_CH1 for OPAMP1, DAC3_CH2 for OPAMP3, DAC4_CH1 for OPAMP4, DAC4_CH2 for OPAMP5, DAC3_CH1 for OPAMP6)
  158. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  159. /**
  160. * @}
  161. */
  162. /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
  163. * @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with negative gain or bias.
  164. * Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin).
  165. * @{
  166. */
  167. #define LL_OPAMP_INPUT_INVERT_IO0 (0x00000000UL) /*!< OPAMP inverting input connected to I/O VINM0
  168. (PA3 for OPAMP1, PA5 for OPAMP2, PB2 for OPAMP3, PB10 for OPAMP4, PB15 for OPAMP5, PA1 for OPAMP6)
  169. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  170. #define LL_OPAMP_INPUT_INVERT_IO1 OPAMP_CSR_VMSEL_0 /*!< OPAMP inverting input connected to I/0 VINM1
  171. (PC5 for OPAMP1, PC5 for OPAMP2, PB10 for OPAMP3, PB8 for OPAMP4, PA3 for OPAMP5, PB1 for OPAMP6)
  172. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  173. #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).
  174. Note: On this STM32 series, this literal include cases of value 0x11 for mode follower and value 0x10 for mode PGA. */
  175. /**
  176. * @}
  177. */
  178. /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING_SECONDARY OPAMP input non-inverting secondary
  179. * @{
  180. */
  181. #define LL_OPAMP_INPUT_NONINVERT_IO0_SEC (0x00000000UL) /*!< OPAMP secondary non inverting input connected to I/O VINP0
  182. (PA1 for OPAMP1, PA7 for OPAMP2, PB0 for OPAMP3, PB13 for OPAMP4, PB14 for OPAMP5, PB12 for OPAMP6)
  183. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  184. #define LL_OPAMP_INPUT_NONINVERT_IO1_SEC OPAMP_TCMR_VPSSEL_0 /*!< OPAMP secondary non inverting input connected to I/O VINP1
  185. (PA3 for OPAMP1, PB14 for OPAMP2, PB13 for OPAMP3, PD11 for OPAMP4, PD12 for OPAMP5, PD9 for OPAMP6)
  186. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  187. #define LL_OPAMP_INPUT_NONINVERT_IO2_SEC OPAMP_TCMR_VPSSEL_1 /*!< OPAMP secondary non inverting input connected to I/O VINP2
  188. (PA7 for OPAMP1, PB0 for OPAMP2, PA1 for OPAMP3, PB11 for OPAMP4, PC3 for OPAMP5, PB13 for OPAMP6)
  189. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  190. #define LL_OPAMP_INPUT_NONINVERT_IO3_SEC OPAMP_TCMR_VPSSEL /*!< OPAMP secondary non inverting input connected to I/O VINP3
  191. (PD14 for OPAMP2) */
  192. #define LL_OPAMP_INPUT_NONINVERT_DAC_SEC OPAMP_TCMR_VPSSEL /*!< OPAMP secondary non inverting input connected internally to DAC channel
  193. (DAC3_CH1 for OPAMP1, DAC3_CH2 for OPAMP3, DAC4_CH1 for OPAMP4, DAC4_CH2 for OPAMP5, DAC3_CH1 for OPAMP6)
  194. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  195. /**
  196. * @}
  197. */
  198. /** @defgroup OPAMP_LL_EC_INPUT_INVERTING_SECONDARY OPAMP input inverting secondary
  199. * @note OPAMP inverting input is used with OPAMP in mode standalone or PGA with negative gain or bias.
  200. * Otherwise (OPAMP in mode follower), OPAMP inverting input is not used (not connected to GPIO pin).
  201. * @{
  202. */
  203. #define LL_OPAMP_INPUT_INVERT_IO0_SEC (0x00000000UL) /*!< OPAMP secondary mode is standalone mode - Only applicable if @ref LL_OPAMP_MODE_STANDALONE
  204. has been configured by call to @ref LL_OPAMP_Init() or @ref LL_OPAMP_SetFunctionalMode().
  205. OPAMP secondary inverting input connected to I/O VINM0.
  206. (PA3 for OPAMP1, PA5 for OPAMP2, PB2 for OPAMP3, PB10 for OPAMP4, PB15 for OPAMP5, PA1 for OPAMP6)
  207. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  208. #define LL_OPAMP_INPUT_INVERT_IO1_SEC OPAMP_TCMR_VMSSEL /*!< OPAMP secondary mode is standalone mode - Only applicable if @ref LL_OPAMP_MODE_STANDALONE
  209. has been configured by call to @ref LL_OPAMP_Init() or @ref LL_OPAMP_SetFunctionalMode().
  210. OPAMP secondary inverting input connected to I/0 VINM1
  211. (PC5 for OPAMP1, PC5 for OPAMP2, PB10 for OPAMP3, PB8 for OPAMP4, PA3 for OPAMP5, PB1 for OPAMP6)
  212. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  213. #define LL_OPAMP_INPUT_INVERT_PGA_SEC (0x00000000UL) /*!< OPAMP secondary mode is PGA mode - Only applicable if configured mode through call to @ref LL_OPAMP_Init()
  214. or @ref LL_OPAMP_SetFunctionalMode() is NOT @ref LL_OPAMP_MODE_STANDALONE.
  215. OPAMP secondary inverting input is:
  216. - Not connected if configured mode is @ref LL_OPAMP_MODE_FOLLOWER or @ref LL_OPAMP_MODE_PGA
  217. - Connected to VINM0 and possibly VINM1 if any of the other modes as been configured
  218. (see @ref OPAMP_LL_EC_FUNCTIONAL_MODE description for more details on PGA connection modes) */
  219. #define LL_OPAMP_INPUT_INVERT_FOLLOWER_SEC OPAMP_TCMR_VMSSEL /*!< OPAMP secondary mode is Follower mode - Only applicable if configured mode through call to @ref LL_OPAMP_Init()
  220. or @ref LL_OPAMP_SetFunctionalMode() is NOT @ref LL_OPAMP_MODE_STANDALONE.
  221. OPAMP secondary inverting input is not connected. */
  222. /**
  223. * @}
  224. */
  225. /** @defgroup OPAMP_LL_EC_INTERNAL_OUPUT_MODE OPAMP internal output mode
  226. * @{
  227. */
  228. #define LL_OPAMP_INTERNAL_OUPUT_DISABLED (0x00000000UL) /*!< OPAMP internal output to ADC disabled. */
  229. #define LL_OPAMP_INTERNAL_OUPUT_ENABLED OPAMP_CSR_OPAMPINTEN /*!< OPAMP internal output to ADC enabled.
  230. - OPAMP1 internal output is connected to ADC1/Channel13
  231. - OPAMP2 internal output is connected to ADC2/Channel16
  232. - OPAMP3 internal output is connected to ADC2/Channel18 & ADC3/Channel13
  233. - OPAMP4 internal output is connected to ADC5/Channel5
  234. - OPAMP5 internal output is connected to ADC5/Channel3
  235. - OPAMP6 internal output is connected to ADC4/Channel17
  236. Note: On this STM32 series, all OPAMPx are not available on all devices. Refer to device datasheet for more details */
  237. /**
  238. * @}
  239. */
  240. /** @defgroup OPAMP_LL_EC_INPUT_MUX_MODE OPAMP inputs multiplexer mode
  241. * @note The switch can be controlled either by a single timer or a combination of them,
  242. * in this case application has to 'ORed' the values below
  243. * ex LL_OPAMP_INPUT_MUX_TIM1_CH6 | LL_OPAMP_INPUT_MUX_TIM20_CH6
  244. * @{
  245. */
  246. #define LL_OPAMP_INPUT_MUX_DISABLE (0x00000000UL) /*!< OPAMP inputs timer controlled multiplexer mode disabled. */
  247. #define LL_OPAMP_INPUT_MUX_TIM1_CH6 OPAMP_TCMR_T1CMEN /*!< OPAMP inputs timer controlled multiplexer mode enabled, controlled by TIM1 OC6. */
  248. #define LL_OPAMP_INPUT_MUX_TIM8_CH6 OPAMP_TCMR_T8CMEN /*!< OPAMP inputs timer controlled multiplexer mode enabled, controlled by TIM8 OC6. */
  249. #define LL_OPAMP_INPUT_MUX_TIM20_CH6 OPAMP_TCMR_T20CMEN /*!< OPAMP inputs timer controlled multiplexer mode enabled, controlled by TIM20 OC6.
  250. Note: On this STM32 series, TIM20 is not available on all devices. Refer to device datasheet for more details */
  251. /**
  252. * @}
  253. */
  254. /** @defgroup OPAMP_LL_EC_POWER_MODE OPAMP PowerMode
  255. * @{
  256. */
  257. #define LL_OPAMP_POWERMODE_NORMALSPEED (0x00000000UL) /*!< OPAMP output in normal mode */
  258. #define LL_OPAMP_POWERMODE_HIGHSPEED OPAMP_CSR_HIGHSPEEDEN /*!< OPAMP output in highspeed mode */
  259. #define LL_OPAMP_POWERMODE_NORMAL LL_OPAMP_POWERMODE_NORMALSPEED /*!< OPAMP power mode normal - Old Naming for compatibility */
  260. /**
  261. * @}
  262. */
  263. /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
  264. * @{
  265. */
  266. #define LL_OPAMP_TRIMMING_FACTORY (0x00000000UL) /*!< OPAMP trimming factors set to factory values */
  267. #define LL_OPAMP_TRIMMING_USER OPAMP_CSR_USERTRIM /*!< OPAMP trimming factors set to user values */
  268. /**
  269. * @}
  270. */
  271. /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
  272. * @{
  273. */
  274. #define LL_OPAMP_TRIMMING_NMOS_VREF_90PC_VDDA (OPAMP_CSR_TRIMOFFSETN | OPAMP_CSR_CALSEL_1 | OPAMP_CSR_CALSEL_0) /*!< 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). */
  275. #define LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA (OPAMP_CSR_TRIMOFFSETN | OPAMP_CSR_CALSEL_1 ) /*!< OPAMP trimming of transistors differential pair NMOS (internal reference voltage set to 0.5*Vdda). */
  276. #define LL_OPAMP_TRIMMING_PMOS_VREF_10PC_VDDA (OPAMP_CSR_TRIMOFFSETP | OPAMP_CSR_CALSEL_0) /*!< 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). */
  277. #define LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA (OPAMP_CSR_TRIMOFFSETP ) /*!< OPAMP trimming of transistors differential pair PMOS (internal reference voltage set to 0.33*Vdda). */
  278. #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). */
  279. #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). */
  280. /**
  281. * @}
  282. */
  283. /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays
  284. * @note Only OPAMP peripheral HW delays are defined in OPAMP LL driver driver,
  285. * not timeout values.
  286. * For details on delays values, refer to descriptions in source code
  287. * above each literal definition.
  288. * @{
  289. */
  290. /* Delay for OPAMP startup time (transition from state disable to enable). */
  291. /* Note: OPAMP startup time depends on board application environment: */
  292. /* impedance connected to OPAMP output. */
  293. /* The delay below is specified under conditions: */
  294. /* - OPAMP in functional mode follower */
  295. /* - load impedance of 4kOhm (min), 50pF (max) */
  296. /* Literal set to maximum value (refer to device datasheet, */
  297. /* parameter "tWAKEUP"). */
  298. /* Unit: us */
  299. #define LL_OPAMP_DELAY_STARTUP_US (6) /*!< Delay for OPAMP startup time */
  300. /**
  301. * @}
  302. */
  303. /**
  304. * @}
  305. */
  306. /* Exported macro ------------------------------------------------------------*/
  307. /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
  308. * @{
  309. */
  310. /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
  311. * @{
  312. */
  313. /**
  314. * @brief Write a value in OPAMP register
  315. * @param __INSTANCE__ OPAMP Instance
  316. * @param __REG__ Register to be written
  317. * @param __VALUE__ Value to be written in the register
  318. * @retval None
  319. */
  320. #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  321. /**
  322. * @brief Read a value in OPAMP register
  323. * @param __INSTANCE__ OPAMP Instance
  324. * @param __REG__ Register to be read
  325. * @retval Register value
  326. */
  327. #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
  328. /**
  329. * @}
  330. */
  331. /**
  332. * @}
  333. */
  334. /* Exported functions --------------------------------------------------------*/
  335. /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
  336. * @{
  337. */
  338. /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
  339. * @{
  340. */
  341. /**
  342. * @brief Set OPAMP mode calibration or functional.
  343. * @note OPAMP mode corresponds to functional or calibration mode:
  344. * - functional mode: OPAMP operation in standalone, follower, ...
  345. * Set functional mode using function
  346. * @ref LL_OPAMP_SetFunctionalMode().
  347. * - calibration mode: offset calibration of the selected
  348. * transistors differential pair NMOS or PMOS.
  349. * @rmtoll CSR CALON LL_OPAMP_SetMode
  350. * @param OPAMPx OPAMP instance
  351. * @param Mode This parameter can be one of the following values:
  352. * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  353. * @arg @ref LL_OPAMP_MODE_CALIBRATION
  354. * @retval None
  355. */
  356. __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
  357. {
  358. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
  359. }
  360. /**
  361. * @brief Get OPAMP mode calibration or functional.
  362. * @note OPAMP mode corresponds to functional or calibration mode:
  363. * - functional mode: OPAMP operation in standalone, follower, ...
  364. * Set functional mode using function
  365. * @ref LL_OPAMP_SetFunctionalMode().
  366. * - calibration mode: offset calibration of the selected
  367. * transistors differential pair NMOS or PMOS.
  368. * @rmtoll CSR CALON LL_OPAMP_GetMode
  369. * @param OPAMPx OPAMP instance
  370. * @retval Returned value can be one of the following values:
  371. * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  372. * @arg @ref LL_OPAMP_MODE_CALIBRATION
  373. */
  374. __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
  375. {
  376. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
  377. }
  378. /**
  379. * @brief Set OPAMP functional mode by setting internal connections.
  380. * OPAMP operation in standalone, follower, ...
  381. * @note This function reset bit of calibration mode to ensure
  382. * to be in functional mode, in order to have OPAMP parameters
  383. * (inputs selection, ...) set with the corresponding OPAMP mode
  384. * to be effective.
  385. * @rmtoll CSR VMSEL LL_OPAMP_SetFunctionalMode
  386. * @param OPAMPx OPAMP instance
  387. * @param FunctionalMode This parameter can be one of the following values:
  388. * @arg @ref LL_OPAMP_MODE_STANDALONE
  389. * @arg @ref LL_OPAMP_MODE_FOLLOWER
  390. * @arg @ref LL_OPAMP_MODE_PGA
  391. * @arg @ref LL_OPAMP_MODE_PGA_IO0
  392. * @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS
  393. * @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
  394. * @retval None
  395. */
  396. __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
  397. {
  398. /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
  399. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_4 | OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_VMSEL | OPAMP_CSR_CALON, FunctionalMode);
  400. }
  401. /**
  402. * @brief Get OPAMP functional mode from setting of internal connections.
  403. * OPAMP operation in standalone, follower, ...
  404. * @rmtoll CSR VMSEL LL_OPAMP_GetFunctionalMode
  405. * @param OPAMPx OPAMP instance
  406. * @retval Returned value can be one of the following values:
  407. * @arg @ref LL_OPAMP_MODE_STANDALONE
  408. * @arg @ref LL_OPAMP_MODE_FOLLOWER
  409. * @arg @ref LL_OPAMP_MODE_PGA
  410. * @arg @ref LL_OPAMP_MODE_PGA_IO0
  411. * @arg @ref LL_OPAMP_MODE_PGA_IO0_BIAS
  412. * @arg @ref LL_OPAMP_MODE_PGA_IO0_IO1_BIAS
  413. */
  414. __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
  415. {
  416. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_4 | OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_VMSEL));
  417. }
  418. /**
  419. * @brief Set OPAMP PGA gain.
  420. * @note Preliminarily, OPAMP must be set in mode PGA
  421. * using function @ref LL_OPAMP_SetFunctionalMode().
  422. * @rmtoll CSR PGGAIN LL_OPAMP_SetPGAGain
  423. * @param OPAMPx OPAMP instance
  424. * @param PGAGain This parameter can be one of the following values:
  425. * @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1
  426. * @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3
  427. * @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7
  428. * @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15
  429. * @arg @ref LL_OPAMP_PGA_GAIN_32_OR_MINUS_31
  430. * @arg @ref LL_OPAMP_PGA_GAIN_64_OR_MINUS_63
  431. * @retval None
  432. */
  433. __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
  434. {
  435. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0, PGAGain);
  436. }
  437. /**
  438. * @brief Get OPAMP PGA gain.
  439. * @note Preliminarily, OPAMP must be set in mode PGA
  440. * using function @ref LL_OPAMP_SetFunctionalMode().
  441. * @rmtoll CSR PGGAIN LL_OPAMP_GetPGAGain
  442. * @param OPAMPx OPAMP instance
  443. * @retval Returned value can be one of the following values:
  444. * @arg @ref LL_OPAMP_PGA_GAIN_2_OR_MINUS_1
  445. * @arg @ref LL_OPAMP_PGA_GAIN_4_OR_MINUS_3
  446. * @arg @ref LL_OPAMP_PGA_GAIN_8_OR_MINUS_7
  447. * @arg @ref LL_OPAMP_PGA_GAIN_16_OR_MINUS_15
  448. * @arg @ref LL_OPAMP_PGA_GAIN_32_OR_MINUS_31
  449. * @arg @ref LL_OPAMP_PGA_GAIN_64_OR_MINUS_63
  450. */
  451. __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx)
  452. {
  453. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0));
  454. }
  455. /**
  456. * @brief Set OPAMP power mode normal or highspeed.
  457. * @note OPAMP highspeed mode allows output stage to have a better slew rate.
  458. * @rmtoll CSR HIGHSPEEDEN LL_OPAMP_SetPowerMode
  459. * @param OPAMPx OPAMP instance
  460. * @param PowerMode This parameter can be one of the following values:
  461. * @arg @ref LL_OPAMP_POWERMODE_NORMALSPEED
  462. * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
  463. * @retval None
  464. */
  465. __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
  466. {
  467. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_HIGHSPEEDEN, PowerMode);
  468. }
  469. /**
  470. * @brief Get OPAMP power mode normal or highspeed.
  471. * @note OPAMP highspeed mode allows output stage to have a better slew rate.
  472. * @rmtoll CSR HIGHSPEEDEN LL_OPAMP_GetPowerMode
  473. * @param OPAMPx OPAMP instance
  474. * @retval Returned value can be one of the following values:
  475. * @arg @ref LL_OPAMP_POWERMODE_NORMALSPEED
  476. * @arg @ref LL_OPAMP_POWERMODE_HIGHSPEED
  477. */
  478. __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx)
  479. {
  480. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_HIGHSPEEDEN));
  481. }
  482. /**
  483. * @}
  484. */
  485. /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
  486. * @{
  487. */
  488. /**
  489. * @brief Set OPAMP non-inverting input connection.
  490. * @rmtoll CSR VPSEL LL_OPAMP_SetInputNonInverting
  491. * @param OPAMPx OPAMP instance
  492. * @param InputNonInverting This parameter can be one of the following values:
  493. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  494. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1
  495. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2
  496. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3
  497. * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC
  498. * @retval None
  499. */
  500. __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
  501. {
  502. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting);
  503. }
  504. /**
  505. * @brief Get OPAMP non-inverting input connection.
  506. * @rmtoll CSR VPSEL LL_OPAMP_GetInputNonInverting
  507. * @param OPAMPx OPAMP instance
  508. * @retval Returned value can be one of the following values:
  509. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  510. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1
  511. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2
  512. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3
  513. * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC
  514. */
  515. __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
  516. {
  517. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL));
  518. }
  519. /**
  520. * @brief Set OPAMP inverting input connection.
  521. * @note OPAMP inverting input is used with OPAMP in mode standalone
  522. * or PGA with external capacitors for filtering circuit.
  523. * Otherwise (OPAMP in mode follower), OPAMP inverting input
  524. * is not used (not connected to GPIO pin).
  525. * @rmtoll CSR VMSEL LL_OPAMP_SetInputInverting
  526. * @param OPAMPx OPAMP instance
  527. * @param InputInverting This parameter can be one of the following values:
  528. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  529. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
  530. * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  531. * @retval None
  532. */
  533. __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
  534. {
  535. /* Manage cases of OPAMP inverting input not connected (0x10 and 0x11) */
  536. /* to not modify OPAMP mode follower or PGA. */
  537. /* Bit OPAMP_CSR_VMSEL_1 is set by OPAMP mode (follower, PGA). */
  538. MODIFY_REG(OPAMPx->CSR, (~(InputInverting >> 1)) & OPAMP_CSR_VMSEL_0, InputInverting);
  539. }
  540. /**
  541. * @brief Get OPAMP inverting input connection.
  542. * @rmtoll CSR VMSEL LL_OPAMP_GetInputInverting
  543. * @param OPAMPx OPAMP instance
  544. * @retval Returned value can be one of the following values:
  545. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  546. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
  547. * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  548. */
  549. __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
  550. {
  551. uint32_t input_inverting = READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL);
  552. /* Manage cases 0x10 and 0x11 to return the same value: OPAMP inverting */
  553. /* input not connected. */
  554. return (input_inverting & ~((input_inverting >> 1) & OPAMP_CSR_VMSEL_0));
  555. }
  556. /**
  557. * @brief Set OPAMP non-inverting input secondary connection.
  558. * @rmtoll TCMR VPSSEL LL_OPAMP_SetInputNonInvertingSecondary
  559. * @param OPAMPx OPAMP instance
  560. * @param InputNonInverting This parameter can be one of the following values:
  561. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0_SEC
  562. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1_SEC
  563. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2_SEC
  564. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3_SEC
  565. * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC_SEC
  566. * @retval None
  567. */
  568. __STATIC_INLINE void LL_OPAMP_SetInputNonInvertingSecondary(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
  569. {
  570. MODIFY_REG(OPAMPx->TCMR, OPAMP_TCMR_VPSSEL, InputNonInverting);
  571. }
  572. /**
  573. * @brief Get OPAMP non-inverting input secondary connection.
  574. * @rmtoll TCMR VPSSEL LL_OPAMP_GetInputNonInvertingSecondary
  575. * @param OPAMPx OPAMP instance
  576. * @retval Returned value can be one of the following values:
  577. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0_SEC
  578. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1_SEC
  579. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2_SEC
  580. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3_SEC
  581. * @arg @ref LL_OPAMP_INPUT_NONINVERT_DAC_SEC
  582. */
  583. __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInvertingSecondary(OPAMP_TypeDef *OPAMPx)
  584. {
  585. return (uint32_t)(READ_BIT(OPAMPx->TCMR, OPAMP_TCMR_VPSSEL));
  586. }
  587. /**
  588. * @brief Set OPAMP inverting input secondary connection.
  589. * @note OPAMP inverting input is used with OPAMP in mode standalone
  590. * or PGA with external capacitors for filtering circuit.
  591. * Otherwise (OPAMP in mode follower), OPAMP inverting input
  592. * is not used (not connected to GPIO pin).
  593. * @rmtoll TCMR VMSSEL LL_OPAMP_SetInputInvertingSecondary
  594. * @param OPAMPx OPAMP instance
  595. * @param InputInverting This parameter can be one of the following values:
  596. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0_SEC
  597. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1_SEC
  598. * @arg @ref LL_OPAMP_INPUT_INVERT_PGA_SEC
  599. * @arg @ref LL_OPAMP_INPUT_INVERT_FOLLOWER_SEC
  600. * @retval None
  601. */
  602. __STATIC_INLINE void LL_OPAMP_SetInputInvertingSecondary(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
  603. {
  604. MODIFY_REG(OPAMPx->TCMR, OPAMP_TCMR_VMSSEL, InputInverting);
  605. }
  606. /**
  607. * @brief Get OPAMP inverting input secondary connection.
  608. * @rmtoll TCMR VMSSEL LL_OPAMP_GetInputInvertingSecondary
  609. * @param OPAMPx OPAMP instance
  610. * @retval Returned value can be one of the following values:
  611. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0_SEC
  612. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1_SEC
  613. * @arg @ref LL_OPAMP_INPUT_INVERT_PGA_SEC
  614. * @arg @ref LL_OPAMP_INPUT_INVERT_FOLLOWER_SEC
  615. */
  616. __STATIC_INLINE uint32_t LL_OPAMP_GetInputInvertingSecondary(OPAMP_TypeDef *OPAMPx)
  617. {
  618. return (uint32_t)(READ_BIT(OPAMPx->TCMR, OPAMP_TCMR_VMSSEL));
  619. }
  620. /**
  621. * @brief Set OPAMP inputs multiplexer mode.
  622. * @rmtoll TCMR TCMEN LL_OPAMP_SetInputsMuxMode
  623. * @param OPAMPx OPAMP instance
  624. * @param InputsMuxMode This parameter can be one of the following values:
  625. * @arg @ref LL_OPAMP_INPUT_MUX_DISABLE
  626. * @arg @ref LL_OPAMP_INPUT_MUX_TIM1_CH6
  627. * @arg @ref LL_OPAMP_INPUT_MUX_TIM8_CH6
  628. * @arg @ref LL_OPAMP_INPUT_MUX_TIM20_CH6 (1)
  629. * On this STM32 series, this value is not available on all devices. Refer to datasheet for details.
  630. * @retval None
  631. */
  632. __STATIC_INLINE void LL_OPAMP_SetInputsMuxMode(OPAMP_TypeDef *OPAMPx, uint32_t InputsMuxMode)
  633. {
  634. MODIFY_REG(OPAMPx->TCMR, OPAMP_TCMR_T1CMEN | OPAMP_TCMR_T8CMEN | OPAMP_TCMR_T20CMEN, InputsMuxMode);
  635. }
  636. /**
  637. * @brief Get OPAMP inputs multiplexer mode.
  638. * @rmtoll TCMR TCMEN LL_OPAMP_GetInputsMuxMode
  639. * @param OPAMPx OPAMP instance
  640. * @retval Returned value can be one of the following values:
  641. * @arg @ref LL_OPAMP_INPUT_MUX_DISABLE
  642. * @arg @ref LL_OPAMP_INPUT_MUX_TIM1_CH6
  643. * @arg @ref LL_OPAMP_INPUT_MUX_TIM8_CH6
  644. * @arg @ref LL_OPAMP_INPUT_MUX_TIM20_CH6 (1)
  645. * On this STM32 series, this value is not available on all devices. Refer to datasheet for details.
  646. */
  647. __STATIC_INLINE uint32_t LL_OPAMP_GetInputsMuxMode(OPAMP_TypeDef *OPAMPx)
  648. {
  649. return (uint32_t)(READ_BIT(OPAMPx->TCMR, OPAMP_TCMR_T1CMEN | OPAMP_TCMR_T8CMEN | OPAMP_TCMR_T20CMEN));
  650. }
  651. /**
  652. * @brief Set OPAMP internal output.
  653. * @note OPAMP internal output is used to link OPAMP output to ADC input internally.
  654. * @rmtoll CSR OPAMPINTEN LL_OPAMP_SetInternalOutput
  655. * @param OPAMPx OPAMP instance
  656. * @param InternalOutput This parameter can be one of the following values:
  657. * @arg @ref LL_OPAMP_INTERNAL_OUPUT_DISABLED
  658. * @arg @ref LL_OPAMP_INTERNAL_OUPUT_ENABLED
  659. * @retval None
  660. */
  661. __STATIC_INLINE void LL_OPAMP_SetInternalOutput(OPAMP_TypeDef *OPAMPx, uint32_t InternalOutput)
  662. {
  663. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAMPINTEN, InternalOutput);
  664. }
  665. /**
  666. * @brief Get OPAMP internal output state.
  667. * @rmtoll CSR OPAMPINTEN LL_OPAMP_GetInternalOutput
  668. * @param OPAMPx OPAMP instance
  669. * @retval Returned value can be one of the following values:
  670. * @arg @ref LL_OPAMP_INTERNAL_OUPUT_DISABLED
  671. * @arg @ref LL_OPAMP_INTERNAL_OUPUT_ENABLED
  672. */
  673. __STATIC_INLINE uint32_t LL_OPAMP_GetInternalOutput(OPAMP_TypeDef *OPAMPx)
  674. {
  675. return READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPINTEN);
  676. }
  677. /**
  678. * @}
  679. */
  680. /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
  681. * @{
  682. */
  683. /**
  684. * @brief Set OPAMP trimming mode.
  685. * @rmtoll CSR USERTRIM LL_OPAMP_SetTrimmingMode
  686. * @param OPAMPx OPAMP instance
  687. * @param TrimmingMode This parameter can be one of the following values:
  688. * @arg @ref LL_OPAMP_TRIMMING_FACTORY
  689. * @arg @ref LL_OPAMP_TRIMMING_USER
  690. * @retval None
  691. */
  692. __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode)
  693. {
  694. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode);
  695. }
  696. /**
  697. * @brief Get OPAMP trimming mode.
  698. * @rmtoll CSR USERTRIM LL_OPAMP_GetTrimmingMode
  699. * @param OPAMPx OPAMP instance
  700. * @retval Returned value can be one of the following values:
  701. * @arg @ref LL_OPAMP_TRIMMING_FACTORY
  702. * @arg @ref LL_OPAMP_TRIMMING_USER
  703. */
  704. __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx)
  705. {
  706. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM));
  707. }
  708. /**
  709. * @brief Set OPAMP offset to calibrate the selected transistors
  710. * differential pair NMOS or PMOS.
  711. * @note Preliminarily, OPAMP must be set in mode calibration
  712. * using function @ref LL_OPAMP_SetMode().
  713. * @rmtoll CSR CALSEL LL_OPAMP_SetCalibrationSelection
  714. * @param OPAMPx OPAMP instance
  715. * @param TransistorsDiffPair This parameter can be one of the following values:
  716. * @arg @ref LL_OPAMP_TRIMMING_NMOS (1)
  717. * @arg @ref LL_OPAMP_TRIMMING_PMOS (1)
  718. * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
  719. * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
  720. *
  721. * (1) Default parameters to be used for calibration
  722. * using two trimming steps (one with each transistors differential
  723. * pair NMOS and PMOS)
  724. * @retval None
  725. */
  726. __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
  727. {
  728. /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */
  729. /* containing other bits reserved for other purpose. */
  730. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, (TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK));
  731. }
  732. /**
  733. * @brief Get OPAMP offset to calibrate the selected transistors
  734. * differential pair NMOS or PMOS.
  735. * @note Preliminarily, OPAMP must be set in mode calibration
  736. * using function @ref LL_OPAMP_SetMode().
  737. * @rmtoll CSR CALSEL LL_OPAMP_GetCalibrationSelection
  738. * @param OPAMPx OPAMP instance
  739. * @retval Returned value can be one of the following values:
  740. * @arg @ref LL_OPAMP_TRIMMING_NMOS (1)
  741. * @arg @ref LL_OPAMP_TRIMMING_PMOS (1)
  742. * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
  743. * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
  744. *
  745. * (1) Default parameters to be used for calibration
  746. * using two trimming steps (one with each transistors differential
  747. * pair NMOS and PMOS)
  748. */
  749. __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
  750. {
  751. uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
  752. return (CalibrationSelection |
  753. (((CalibrationSelection & OPAMP_CSR_CALSEL_1) == 0UL) ? OPAMP_CSR_TRIMOFFSETP : OPAMP_CSR_TRIMOFFSETN));
  754. }
  755. /**
  756. * @brief Get OPAMP calibration result of toggling output.
  757. * @note This functions returns:
  758. * 0 if OPAMP calibration output is reset
  759. * 1 if OPAMP calibration output is set
  760. * @rmtoll CSR OUTCAL LL_OPAMP_IsCalibrationOutputSet
  761. * @param OPAMPx OPAMP instance
  762. * @retval State of bit (1 or 0).
  763. */
  764. __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
  765. {
  766. return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OUTCAL) == OPAMP_CSR_OUTCAL) ? 1UL : 0UL);
  767. }
  768. /**
  769. * @brief Set OPAMP trimming factor for the selected transistors
  770. * differential pair NMOS or PMOS, corresponding to the selected
  771. * power mode.
  772. * @rmtoll CSR TRIMOFFSETN LL_OPAMP_SetTrimmingValue\n
  773. * CSR TRIMOFFSETP LL_OPAMP_SetTrimmingValue
  774. * @param OPAMPx OPAMP instance
  775. * @param TransistorsDiffPair This parameter can be one of the following values:
  776. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  777. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  778. * @param TrimmingValue 0x00...0x1F
  779. * @retval None
  780. */
  781. __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair,
  782. uint32_t TrimmingValue)
  783. {
  784. MODIFY_REG(OPAMPx->CSR,
  785. (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK),
  786. TrimmingValue << ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_CSR_TRIMOFFSETN_Pos : OPAMP_CSR_TRIMOFFSETP_Pos));
  787. }
  788. /**
  789. * @brief Get OPAMP trimming factor for the selected transistors
  790. * differential pair NMOS or PMOS, corresponding to the selected
  791. * power mode.
  792. * @rmtoll CSR TRIMOFFSETN LL_OPAMP_GetTrimmingValue\n
  793. * CSR TRIMOFFSETP LL_OPAMP_GetTrimmingValue
  794. * @param OPAMPx OPAMP instance
  795. * @param TransistorsDiffPair This parameter can be one of the following values:
  796. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  797. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  798. * @retval 0x0...0x1F
  799. */
  800. __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
  801. {
  802. return (uint32_t)(READ_BIT(OPAMPx->CSR, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
  803. >> ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_CSR_TRIMOFFSETN_Pos : OPAMP_CSR_TRIMOFFSETP_Pos));
  804. }
  805. /**
  806. * @}
  807. */
  808. /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
  809. * @{
  810. */
  811. /**
  812. * @brief Enable OPAMP instance.
  813. * @note After enable from off state, OPAMP requires a delay
  814. * to fulfill wake up time specification.
  815. * Refer to device datasheet, parameter "tWAKEUP".
  816. * @rmtoll CSR OPAMPXEN LL_OPAMP_Enable
  817. * @param OPAMPx OPAMP instance
  818. * @retval None
  819. */
  820. __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
  821. {
  822. SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
  823. }
  824. /**
  825. * @brief Disable OPAMP instance.
  826. * @rmtoll CSR OPAMPXEN LL_OPAMP_Disable
  827. * @param OPAMPx OPAMP instance
  828. * @retval None
  829. */
  830. __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
  831. {
  832. CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
  833. }
  834. /**
  835. * @brief Get OPAMP instance enable state
  836. * (0: OPAMP is disabled, 1: OPAMP is enabled)
  837. * @rmtoll CSR OPAMPXEN LL_OPAMP_IsEnabled
  838. * @param OPAMPx OPAMP instance
  839. * @retval State of bit (1 or 0).
  840. */
  841. __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx)
  842. {
  843. return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN)) ? 1UL : 0UL);
  844. }
  845. /**
  846. * @brief Lock OPAMP instance.
  847. * @note Once locked, OPAMP configuration can be accessed in read-only.
  848. * @note The only way to unlock the OPAMP is a device hardware reset.
  849. * @rmtoll CSR LOCK LL_OPAMP_Lock
  850. * @param OPAMPx OPAMP instance
  851. * @retval None
  852. */
  853. __STATIC_INLINE void LL_OPAMP_Lock(OPAMP_TypeDef *OPAMPx)
  854. {
  855. SET_BIT(OPAMPx->CSR, OPAMP_CSR_LOCK);
  856. }
  857. /**
  858. * @brief Get OPAMP lock state
  859. * (0: OPAMP is unlocked, 1: OPAMP is locked).
  860. * @note Once locked, OPAMP configuration can be accessed in read-only.
  861. * @note The only way to unlock the OPAMP is a device hardware reset.
  862. * @rmtoll CSR LOCK LL_OPAMP_IsLocked
  863. * @param OPAMPx OPAMP instance
  864. * @retval State of bit (1 or 0).
  865. */
  866. __STATIC_INLINE uint32_t LL_OPAMP_IsLocked(OPAMP_TypeDef *OPAMPx)
  867. {
  868. return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_LOCK) == (OPAMP_CSR_LOCK)) ? 1UL : 0UL);
  869. }
  870. /**
  871. * @brief Lock OPAMP instance timer controlled mux
  872. * @note Once locked, OPAMP timer controlled mux configuration can be accessed in read-only.
  873. * @note The only way to unlock the OPAMP timer controlled mux is a device hardware reset.
  874. * @rmtoll TCMR LOCK LL_OPAMP_LockTimerMux
  875. * @param OPAMPx OPAMP instance
  876. * @retval None
  877. */
  878. __STATIC_INLINE void LL_OPAMP_LockTimerMux(OPAMP_TypeDef *OPAMPx)
  879. {
  880. SET_BIT(OPAMPx->TCMR, OPAMP_TCMR_LOCK);
  881. }
  882. /**
  883. * @brief Get OPAMP timer controlled mux lock state
  884. * (0: OPAMP timer controlled mux is unlocked, 1: OPAMP timer controlled mux is locked).
  885. * @note Once locked, OPAMP timer controlled mux configuration can be accessed in read-only.
  886. * @note The only way to unlock the OPAMP timer controlled mux is a device hardware reset.
  887. * @rmtoll TCMR LOCK LL_OPAMP_IsTimerMuxLocked
  888. * @param OPAMPx OPAMP instance
  889. * @retval State of bit (1 or 0).
  890. */
  891. __STATIC_INLINE uint32_t LL_OPAMP_IsTimerMuxLocked(OPAMP_TypeDef *OPAMPx)
  892. {
  893. return ((READ_BIT(OPAMPx->TCMR, OPAMP_TCMR_LOCK) == (OPAMP_TCMR_LOCK)) ? 1UL : 0UL);
  894. }
  895. /**
  896. * @}
  897. */
  898. #if defined(USE_FULL_LL_DRIVER)
  899. /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
  900. * @{
  901. */
  902. ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
  903. ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  904. void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  905. /**
  906. * @}
  907. */
  908. #endif /* USE_FULL_LL_DRIVER */
  909. /**
  910. * @}
  911. */
  912. /**
  913. * @}
  914. */
  915. #endif /* OPAMP1 || OPAMP2 || OPAMP3 || OPAMP4 || OPAMP5 || OPAMP6 */
  916. /**
  917. * @}
  918. */
  919. #ifdef __cplusplus
  920. }
  921. #endif
  922. #endif /* STM32G4xx_LL_OPAMP_H */