stm32f3xx_ll_opamp.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_ll_opamp.h
  4. * @author MCD Application Team
  5. * @brief Header file of OPAMP LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 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 STM32F3xx_LL_OPAMP_H
  20. #define STM32F3xx_LL_OPAMP_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32f3xx.h"
  26. /** @addtogroup STM32F3xx_LL_Driver
  27. * @{
  28. */
  29. #if defined (OPAMP1) || defined (OPAMP2) || defined (OPAMP3) || defined (OPAMP4)
  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. ((uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U))))
  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 FunctionalMode; /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
  77. This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
  78. @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain().
  79. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
  80. uint32_t InputNonInverting; /*!< Set OPAMP input non-inverting connection.
  81. This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
  82. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
  83. uint32_t InputInverting; /*!< Set OPAMP inverting input connection.
  84. This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
  85. @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.
  86. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
  87. } LL_OPAMP_InitTypeDef;
  88. /**
  89. * @}
  90. */
  91. #endif /* USE_FULL_LL_DRIVER */
  92. /* Exported constants --------------------------------------------------------*/
  93. /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
  94. * @{
  95. */
  96. /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
  97. * @{
  98. */
  99. #define LL_OPAMP_MODE_FUNCTIONAL (0x00000000U) /*!< OPAMP functional mode */
  100. #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_CALON) /*!< OPAMP calibration mode */
  101. /**
  102. * @}
  103. */
  104. /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
  105. * @{
  106. */
  107. #define LL_OPAMP_MODE_STANDALONE (0x00000000U) /*!< OPAMP functional mode, OPAMP operation in standalone */
  108. #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_VMSEL_1 | OPAMP_CSR_VMSEL_0) /*!< OPAMP functional mode, OPAMP operation in follower */
  109. #define LL_OPAMP_MODE_PGA (OPAMP_CSR_VMSEL_1) /*!< OPAMP functional mode, OPAMP operation in PGA */
  110. #define LL_OPAMP_MODE_PGA_EXT_FILT_IO0 (OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_VMSEL_1) /*!< OPAMP functional mode, OPAMP operation in PGA with external filtering on OPAMP input IO0. */
  111. #define LL_OPAMP_MODE_PGA_EXT_FILT_IO1 (OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL_1) /*!< OPAMP functional mode, OPAMP operation in PGA with external filtering on OPAMP input IO1. */
  112. /**
  113. * @}
  114. */
  115. /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
  116. * @{
  117. */
  118. #define LL_OPAMP_PGA_GAIN_2 (0x00000000U) /*!< OPAMP PGA gain 2 */
  119. #define LL_OPAMP_PGA_GAIN_4 (OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 4 */
  120. #define LL_OPAMP_PGA_GAIN_8 (OPAMP_CSR_PGGAIN_1) /*!< OPAMP PGA gain 8 */
  121. #define LL_OPAMP_PGA_GAIN_16 (OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0 ) /*!< OPAMP PGA gain 16 */
  122. /**
  123. * @}
  124. */
  125. /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
  126. * @{
  127. */
  128. #define LL_OPAMP_INPUT_NONINVERT_IO0 (OPAMP_CSR_VPSEL) /*!< OPAMP non inverting input connected to GPIO pin (pin PA1 for OPAMP1, pin PA7 for OPAMP2, pin PB0 for OPAMP3, pin PB13 for OPAMP4) */
  129. #define LL_OPAMP_INPUT_NONINVERT_IO1 (0x00000000) /*!< OPAMP non inverting input connected to GPIO pin (pin PA7 for OPAMP1, pin PD14 for OPAMP2, pin PB13 for OPAMP3, pin PD11 for OPAMP4) */
  130. #define LL_OPAMP_INPUT_NONINVERT_IO2 (OPAMP_CSR_VPSEL_1) /*!< OPAMP non inverting input connected to GPIO pin (pin PA3 for OPAMP1, pin PB0 for OPAMP2, pin PA1 for OPAMP3, pin PA4 for OPAMP4) */
  131. #define LL_OPAMP_INPUT_NONINVERT_IO3 (OPAMP_CSR_VPSEL_0) /*!< OPAMP non inverting input connected to GPIO pin (pin PA5 for OPAMP1, pin PB14 for OPAMP2, pin PA5 for OPAMP3, pin PB11 for OPAMP4) */
  132. #define LL_OPAMP_INPUT_NONINV_DAC1_CH1 (LL_OPAMP_INPUT_NONINVERT_IO3) /*!< OPAMP non inverting input connected to DAC1 channel1 output (specific to OPAMP instances: OPAMP4) */
  133. #define LL_OPAMP_INPUT_NONINV_DAC1_CH2 (LL_OPAMP_INPUT_NONINVERT_IO3) /*!< OPAMP non inverting input connected to DAC1 channel2 output (specific to OPAMP instances: OPAMP1, OPAMP3) */
  134. /**
  135. * @}
  136. */
  137. /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
  138. * @{
  139. */
  140. #define LL_OPAMP_INPUT_INVERT_IO0 (0x00000000U) /*!< OPAMP inverting input connected to GPIO pin (pin PC5 for OPAMP1, pin PC5 for OPAMP2, pin PB10 for OPAMP3, pin PB10 for OPAMP4). 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). */
  141. #define LL_OPAMP_INPUT_INVERT_IO1 (OPAMP_CSR_VMSEL_0) /*!< OPAMP inverting input connected to GPIO pin (pin PA3 for OPAMP1, pin PA5 for OPAMP2, pin PB2 for OPAMP3, pin PD8 for OPAMP4). 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). */
  142. #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 without external capacitors for filtering). Note: On this STM32 series, this literal include cases of value 0x11 for mode follower and value 0x10 for mode PGA. */
  143. /**
  144. * @}
  145. */
  146. /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING_SECONDARY OPAMP input non-inverting secondary
  147. * @{
  148. */
  149. #define LL_OPAMP_INPUT_NONINVERT_IO0_SEC (LL_OPAMP_INPUT_NONINVERT_IO0 << (OPAMP_CSR_VPSSEL_Pos - OPAMP_CSR_VPSEL_Pos)) /*!< OPAMP non inverting input secondary connected to GPIO pin (pin PA1 for OPAMP1, pin PA7 for OPAMP2, pin PB0 for OPAMP3, pin PB13 for OPAMP4) */
  150. #define LL_OPAMP_INPUT_NONINVERT_IO1_SEC (LL_OPAMP_INPUT_NONINVERT_IO1 << (OPAMP_CSR_VPSSEL_Pos - OPAMP_CSR_VPSEL_Pos)) /*!< OPAMP non inverting input secondary connected to GPIO pin (pin PA7 for OPAMP1, pin PD14 for OPAMP2, pin PB13 for OPAMP3, pin PD11 for OPAMP4) */
  151. #define LL_OPAMP_INPUT_NONINVERT_IO2_SEC (LL_OPAMP_INPUT_NONINVERT_IO2 << (OPAMP_CSR_VPSSEL_Pos - OPAMP_CSR_VPSEL_Pos)) /*!< OPAMP non inverting input secondary connected to GPIO pin (pin PA3 for OPAMP1, pin PB0 for OPAMP2, pin PA1 for OPAMP3, pin PB11 for OPAMP4) */
  152. #define LL_OPAMP_INPUT_NONINVERT_IO3_SEC (LL_OPAMP_INPUT_NONINVERT_IO3 << (OPAMP_CSR_VPSSEL_Pos - OPAMP_CSR_VPSEL_Pos)) /*!< OPAMP non inverting input secondary connected to GPIO pin (pin PA5 for OPAMP1, pin PD14 for OPAMP2, pin PA5 for OPAMP3, pin PA4 for OPAMP4) */
  153. #define LL_OPAMP_INPUT_NONINV_DAC1_CH1_SEC (LL_OPAMP_INPUT_NONINV_DAC1_CH1 << (OPAMP_CSR_VPSSEL_Pos - OPAMP_CSR_VPSEL_Pos)) /*!< OPAMP non inverting input secondary connected to DAC1 channel1 output (specific to OPAMP instances: OPAMP4) */
  154. #define LL_OPAMP_INPUT_NONINV_DAC1_CH2_SEC (LL_OPAMP_INPUT_NONINV_DAC1_CH2 << (OPAMP_CSR_VPSSEL_Pos - OPAMP_CSR_VPSEL_Pos)) /*!< OPAMP non inverting input secondary connected to DAC1 channel2 output (specific to OPAMP instances: OPAMP1, OPAMP3) */
  155. /**
  156. * @}
  157. */
  158. /** @defgroup OPAMP_LL_EC_INPUT_INVERTING_SECONDARY OPAMP input inverting secondary
  159. * @{
  160. */
  161. #define LL_OPAMP_INPUT_INVERT_IO0_SEC (LL_OPAMP_INPUT_INVERT_IO0 << (OPAMP_CSR_VMSSEL_Pos - OPAMP_CSR_VMSEL_Pos)) /*!< OPAMP inverting input secondary connected to GPIO pin (pin PC5 for OPAMP1, pin PC5 for OPAMP2, pin PB10 for OPAMP3, pin PB10 for OPAMP4). 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). */
  162. #define LL_OPAMP_INPUT_INVERT_IO1_SEC (LL_OPAMP_INPUT_INVERT_IO1 << (OPAMP_CSR_VMSSEL_Pos - OPAMP_CSR_VMSEL_Pos)) /*!< OPAMP inverting input secondary connected to GPIO pin (pin PA3 for OPAMP1, pin PA5 for OPAMP2, pin PB2 for OPAMP3, pin PD8 for OPAMP4). 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). */
  163. /**
  164. * @}
  165. */
  166. /** @defgroup OPAMP_LL_EC_INPUT_MUX_MODE OPAMP inputs multiplexer mode
  167. * @{
  168. */
  169. #define LL_OPAMP_INPUT_MUX_DISABLE (0x00000000U) /*!< OPAMP inputs multiplexer mode dosabled. */
  170. #define LL_OPAMP_INPUT_MUX_TIM1_CH6 (OPAMP_CSR_TCMEN) /*!< OPAMP inputs multiplexer mode enabled, controlled by TIM1 CC6. */
  171. /**
  172. * @}
  173. */
  174. /** @defgroup OPAMP_LL_EC_VREF_OUTPUT OPAMP internal reference voltage path state to output
  175. * @{
  176. */
  177. #define LL_OPAMP_VREF_OUTPUT_DISABLE (0x00000000U) /*!< OPAMP internal reference voltage path to output is disabled. */
  178. #define LL_OPAMP_VREF_OUTPUT_ENABLE (OPAMP_CSR_TSTREF) /*!< OPAMP internal reference voltage path to output is enabled. */
  179. /**
  180. * @}
  181. */
  182. /** @defgroup OPAMP_LL_EC_TRIMMING_MODE OPAMP trimming mode
  183. * @{
  184. */
  185. #define LL_OPAMP_TRIMMING_FACTORY (0x00000000U) /*!< OPAMP trimming factors set to factory values */
  186. #define LL_OPAMP_TRIMMING_USER (OPAMP_CSR_USERTRIM) /*!< OPAMP trimming factors set to user values */
  187. /**
  188. * @}
  189. */
  190. /** @defgroup OPAMP_LL_EC_TRIMMING_TRANSISTORS_DIFF_PAIR OPAMP trimming of transistors differential pair NMOS or PMOS
  191. * @{
  192. */
  193. #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). */
  194. #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). */
  195. #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). */
  196. #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). */
  197. #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). */
  198. #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). */
  199. /**
  200. * @}
  201. */
  202. /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays
  203. * @note Only OPAMP peripheral HW delays are defined in OPAMP LL driver driver,
  204. * not timeout values.
  205. * For details on delays values, refer to descriptions in source code
  206. * above each literal definition.
  207. * @{
  208. */
  209. /* Delay for OPAMP startup time (transition from state disable to enable). */
  210. /* Note: OPAMP startup time depends on board application environment: */
  211. /* impedance connected to OPAMP output. */
  212. /* The delay below is specified under conditions: */
  213. /* - OPAMP in functional mode follower */
  214. /* - load impedance of 4kOhm (min), 50pF (max) */
  215. /* Literal set to maximum value (refer to device datasheet, */
  216. /* parameter "tWAKEUP"). */
  217. /* Unit: us */
  218. #define LL_OPAMP_DELAY_STARTUP_US (5U) /*!< Delay for OPAMP startup time */
  219. /**
  220. * @}
  221. */
  222. /**
  223. * @}
  224. */
  225. /* Exported macro ------------------------------------------------------------*/
  226. /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
  227. * @{
  228. */
  229. /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
  230. * @{
  231. */
  232. /**
  233. * @brief Write a value in OPAMP register
  234. * @param __INSTANCE__ OPAMP Instance
  235. * @param __REG__ Register to be written
  236. * @param __VALUE__ Value to be written in the register
  237. * @retval None
  238. */
  239. #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  240. /**
  241. * @brief Read a value in OPAMP register
  242. * @param __INSTANCE__ OPAMP Instance
  243. * @param __REG__ Register to be read
  244. * @retval Register value
  245. */
  246. #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
  247. /**
  248. * @}
  249. */
  250. /**
  251. * @}
  252. */
  253. /* Exported functions --------------------------------------------------------*/
  254. /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
  255. * @{
  256. */
  257. /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
  258. * @{
  259. */
  260. /**
  261. * @brief Set OPAMP mode calibration or functional.
  262. * @note OPAMP mode corresponds to functional or calibration mode:
  263. * - functional mode: OPAMP operation in standalone, follower, ...
  264. * Set functional mode using function
  265. * @ref LL_OPAMP_SetFunctionalMode().
  266. * - calibration mode: offset calibration of the selected
  267. * transistors differential pair NMOS or PMOS.
  268. * @rmtoll CSR CALON LL_OPAMP_SetMode
  269. * @param OPAMPx OPAMP instance
  270. * @param Mode This parameter can be one of the following values:
  271. * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  272. * @arg @ref LL_OPAMP_MODE_CALIBRATION
  273. * @retval None
  274. */
  275. __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
  276. {
  277. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
  278. }
  279. /**
  280. * @brief Get OPAMP mode calibration or functional.
  281. * @note OPAMP mode corresponds to functional or calibration mode:
  282. * - functional mode: OPAMP operation in standalone, follower, ...
  283. * Set functional mode using function
  284. * @ref LL_OPAMP_SetFunctionalMode().
  285. * - calibration mode: offset calibration of the selected
  286. * transistors differential pair NMOS or PMOS.
  287. * @rmtoll CSR CALON LL_OPAMP_GetMode
  288. * @param OPAMPx OPAMP instance
  289. * @retval Returned value can be one of the following values:
  290. * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  291. * @arg @ref LL_OPAMP_MODE_CALIBRATION
  292. */
  293. __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
  294. {
  295. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
  296. }
  297. /**
  298. * @brief Set OPAMP functional mode by setting internal connections.
  299. * OPAMP operation in standalone, follower, ...
  300. * @note This function reset bit of calibration mode to ensure
  301. * to be in functional mode, in order to have OPAMP parameters
  302. * (inputs selection, ...) set with the corresponding OPAMP mode
  303. * to be effective.
  304. * @rmtoll CSR VMSEL LL_OPAMP_SetFunctionalMode
  305. * @param OPAMPx OPAMP instance
  306. * @param FunctionalMode This parameter can be one of the following values:
  307. * @arg @ref LL_OPAMP_MODE_STANDALONE
  308. * @arg @ref LL_OPAMP_MODE_FOLLOWER
  309. * @arg @ref LL_OPAMP_MODE_PGA
  310. * @arg @ref LL_OPAMP_MODE_PGA_EXT_FILT_IO0
  311. * @arg @ref LL_OPAMP_MODE_PGA_EXT_FILT_IO1
  312. * @retval None
  313. */
  314. __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
  315. {
  316. /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
  317. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL | OPAMP_CSR_CALON, FunctionalMode);
  318. }
  319. /**
  320. * @brief Get OPAMP functional mode from setting of internal connections.
  321. * OPAMP operation in standalone, follower, ...
  322. * @rmtoll CSR VMSEL LL_OPAMP_GetFunctionalMode
  323. * @param OPAMPx OPAMP instance
  324. * @retval Returned value can be one of the following values:
  325. * @arg @ref LL_OPAMP_MODE_STANDALONE
  326. * @arg @ref LL_OPAMP_MODE_FOLLOWER
  327. * @arg @ref LL_OPAMP_MODE_PGA
  328. * @arg @ref LL_OPAMP_MODE_PGA_EXT_FILT_IO0
  329. * @arg @ref LL_OPAMP_MODE_PGA_EXT_FILT_IO1
  330. */
  331. __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
  332. {
  333. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_3 | OPAMP_CSR_PGGAIN_2 | OPAMP_CSR_VMSEL));
  334. }
  335. /**
  336. * @brief Set OPAMP PGA gain.
  337. * @note Preliminarily, OPAMP must be set in mode PGA
  338. * using function @ref LL_OPAMP_SetFunctionalMode().
  339. * @rmtoll CSR PGGAIN LL_OPAMP_SetPGAGain
  340. * @param OPAMPx OPAMP instance
  341. * @param PGAGain This parameter can be one of the following values:
  342. * @arg @ref LL_OPAMP_PGA_GAIN_2
  343. * @arg @ref LL_OPAMP_PGA_GAIN_4
  344. * @arg @ref LL_OPAMP_PGA_GAIN_8
  345. * @arg @ref LL_OPAMP_PGA_GAIN_16
  346. * @retval None
  347. */
  348. __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
  349. {
  350. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0, PGAGain);
  351. }
  352. /**
  353. * @brief Get OPAMP PGA gain.
  354. * @note Preliminarily, OPAMP must be set in mode PGA
  355. * using function @ref LL_OPAMP_SetFunctionalMode().
  356. * @rmtoll CSR PGGAIN LL_OPAMP_GetPGAGain
  357. * @param OPAMPx OPAMP instance
  358. * @retval Returned value can be one of the following values:
  359. * @arg @ref LL_OPAMP_PGA_GAIN_2
  360. * @arg @ref LL_OPAMP_PGA_GAIN_4
  361. * @arg @ref LL_OPAMP_PGA_GAIN_8
  362. * @arg @ref LL_OPAMP_PGA_GAIN_16
  363. */
  364. __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx)
  365. {
  366. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0));
  367. }
  368. /**
  369. * @}
  370. */
  371. /** @defgroup OPAMP_LL_EF_CONFIGURATION_INPUTS Configuration of OPAMP inputs
  372. * @{
  373. */
  374. /**
  375. * @brief Set OPAMP non-inverting input connection.
  376. * @rmtoll CSR VPSEL LL_OPAMP_SetInputNonInverting
  377. * @param OPAMPx OPAMP instance
  378. * @param InputNonInverting This parameter can be one of the following values:
  379. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  380. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1
  381. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2
  382. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3
  383. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1 (1)
  384. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH2 (2)
  385. *
  386. * (1) Parameter specific to OPAMP instances: OPAMP4.\n
  387. * (2) Parameter specific to OPAMP instances: OPAMP1, OPAMP3.
  388. * @retval None
  389. */
  390. __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
  391. {
  392. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting);
  393. }
  394. /**
  395. * @brief Get OPAMP non-inverting input connection.
  396. * @rmtoll CSR VPSEL LL_OPAMP_GetInputNonInverting
  397. * @param OPAMPx OPAMP instance
  398. * @retval Returned value can be one of the following values:
  399. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  400. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1
  401. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2
  402. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3
  403. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1 (1)
  404. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH2 (2)
  405. *
  406. * (1) Parameter specific to OPAMP instances: OPAMP4.\n
  407. * (2) Parameter specific to OPAMP instances: OPAMP1, OPAMP3.
  408. */
  409. __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
  410. {
  411. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL));
  412. }
  413. /**
  414. * @brief Set OPAMP inverting input connection.
  415. * @note OPAMP inverting input is used with OPAMP in mode standalone
  416. * or PGA with external capacitors for filtering circuit.
  417. * Otherwise (OPAMP in mode follower), OPAMP inverting input
  418. * is not used (not connected to GPIO pin).
  419. * @rmtoll CSR VMSEL LL_OPAMP_SetInputInverting
  420. * @param OPAMPx OPAMP instance
  421. * @param InputInverting This parameter can be one of the following values:
  422. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  423. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
  424. * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  425. * @retval None
  426. */
  427. __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
  428. {
  429. /* Manage cases of OPAMP inverting input not connected (0x10 and 0x11) */
  430. /* to not modify OPAMP mode follower or PGA. */
  431. /* Bit OPAMP_CSR_VMSEL_1 is set by OPAMP mode (follower, PGA). */
  432. MODIFY_REG(OPAMPx->CSR, (~(InputInverting >> 1)) & OPAMP_CSR_VMSEL_0, InputInverting);
  433. }
  434. /**
  435. * @brief Get OPAMP inverting input connection.
  436. * @rmtoll CSR VMSEL LL_OPAMP_GetInputInverting
  437. * @param OPAMPx OPAMP instance
  438. * @retval Returned value can be one of the following values:
  439. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  440. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
  441. * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  442. */
  443. __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
  444. {
  445. uint32_t input_inverting = READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL);
  446. /* Manage cases 0x10 and 0x11 to return the same value: OPAMP inverting */
  447. /* input not connected. */
  448. return (input_inverting & ~((input_inverting >> 1) & OPAMP_CSR_VMSEL_0));
  449. }
  450. /**
  451. * @brief Set OPAMP non-inverting input secondary connection.
  452. * @rmtoll CSR VPSSEL LL_OPAMP_SetInputNonInvertingSecondary
  453. * @param OPAMPx OPAMP instance
  454. * @param InputNonInverting This parameter can be one of the following values:
  455. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0_SEC
  456. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1_SEC
  457. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2_SEC
  458. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3_SEC
  459. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1_SEC (1)
  460. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH2_SEC (2)
  461. *
  462. * (1) Parameter specific to OPAMP instances: OPAMP4.\n
  463. * (2) Parameter specific to OPAMP instances: OPAMP1, OPAMP3.
  464. * @retval None
  465. */
  466. __STATIC_INLINE void LL_OPAMP_SetInputNonInvertingSecondary(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
  467. {
  468. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSSEL, InputNonInverting);
  469. }
  470. /**
  471. * @brief Get OPAMP non-inverting input secondary connection.
  472. * @rmtoll CSR VPSSEL LL_OPAMP_GetInputNonInvertingSecondary
  473. * @param OPAMPx OPAMP instance
  474. * @retval Returned value can be one of the following values:
  475. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0_SEC
  476. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO1_SEC
  477. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO2_SEC
  478. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO3_SEC
  479. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1_SEC (1)
  480. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH2_SEC (2)
  481. *
  482. * (1) Parameter specific to OPAMP instances: OPAMP4.\n
  483. * (2) Parameter specific to OPAMP instances: OPAMP1, OPAMP3.
  484. */
  485. __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInvertingSecondary(OPAMP_TypeDef *OPAMPx)
  486. {
  487. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSSEL));
  488. }
  489. /**
  490. * @brief Set OPAMP inverting input secondary connection.
  491. * @note OPAMP inverting input is used with OPAMP in mode standalone
  492. * or PGA with external capacitors for filtering circuit.
  493. * Otherwise (OPAMP in mode follower), OPAMP inverting input
  494. * is not used (not connected to GPIO pin).
  495. * @rmtoll CSR VMSSEL LL_OPAMP_SetInputInvertingSecondary
  496. * @param OPAMPx OPAMP instance
  497. * @param InputInverting This parameter can be one of the following values:
  498. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0_SEC
  499. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1_SEC
  500. * @retval None
  501. */
  502. __STATIC_INLINE void LL_OPAMP_SetInputInvertingSecondary(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
  503. {
  504. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VMSSEL, InputInverting);
  505. }
  506. /**
  507. * @brief Get OPAMP inverting input secondary connection.
  508. * @rmtoll CSR VMSSEL LL_OPAMP_GetInputInvertingSecondary
  509. * @param OPAMPx OPAMP instance
  510. * @retval Returned value can be one of the following values:
  511. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0_SEC
  512. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1_SEC
  513. */
  514. __STATIC_INLINE uint32_t LL_OPAMP_GetInputInvertingSecondary(OPAMP_TypeDef *OPAMPx)
  515. {
  516. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSSEL));
  517. }
  518. /**
  519. * @brief Set OPAMP inputs multiplexer mode.
  520. * @rmtoll CSR TCMEN LL_OPAMP_SetInputsMuxMode
  521. * @param OPAMPx OPAMP instance
  522. * @param InputsMuxMode This parameter can be one of the following values:
  523. * @arg @ref LL_OPAMP_INPUT_MUX_DISABLE
  524. * @arg @ref LL_OPAMP_INPUT_MUX_TIM1_CH6
  525. * @retval None
  526. */
  527. __STATIC_INLINE void LL_OPAMP_SetInputsMuxMode(OPAMP_TypeDef *OPAMPx, uint32_t InputsMuxMode)
  528. {
  529. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_TCMEN, InputsMuxMode);
  530. }
  531. /**
  532. * @brief Get OPAMP inputs multiplexer mode.
  533. * @rmtoll CSR TCMEN LL_OPAMP_GetInputsMuxMode
  534. * @param OPAMPx OPAMP instance
  535. * @retval Returned value can be one of the following values:
  536. * @arg @ref LL_OPAMP_INPUT_MUX_DISABLE
  537. * @arg @ref LL_OPAMP_INPUT_MUX_TIM1_CH6
  538. */
  539. __STATIC_INLINE uint32_t LL_OPAMP_GetInputsMuxMode(OPAMP_TypeDef *OPAMPx)
  540. {
  541. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_TCMEN));
  542. }
  543. /**
  544. * @}
  545. */
  546. /** @defgroup OPAMP_LL_EF_OPAMP_TRIMMING Configuration and operation of OPAMP trimming
  547. * @{
  548. */
  549. /**
  550. * @brief Set OPAMP trimming mode.
  551. * @rmtoll CSR USERTRIM LL_OPAMP_SetTrimmingMode
  552. * @param OPAMPx OPAMP instance
  553. * @param TrimmingMode This parameter can be one of the following values:
  554. * @arg @ref LL_OPAMP_TRIMMING_FACTORY
  555. * @arg @ref LL_OPAMP_TRIMMING_USER
  556. * @retval None
  557. */
  558. __STATIC_INLINE void LL_OPAMP_SetTrimmingMode(OPAMP_TypeDef *OPAMPx, uint32_t TrimmingMode)
  559. {
  560. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_USERTRIM, TrimmingMode);
  561. }
  562. /**
  563. * @brief Get OPAMP trimming mode.
  564. * @rmtoll CSR USERTRIM LL_OPAMP_GetTrimmingMode
  565. * @param OPAMPx OPAMP instance
  566. * @retval Returned value can be one of the following values:
  567. * @arg @ref LL_OPAMP_TRIMMING_FACTORY
  568. * @arg @ref LL_OPAMP_TRIMMING_USER
  569. */
  570. __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingMode(OPAMP_TypeDef *OPAMPx)
  571. {
  572. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_USERTRIM));
  573. }
  574. /**
  575. * @brief Set OPAMP offset to calibrate the selected transistors
  576. * differential pair NMOS or PMOS.
  577. * @note Preliminarily, OPAMP must be set in mode calibration
  578. * using function @ref LL_OPAMP_SetMode().
  579. * @rmtoll CSR CALSEL LL_OPAMP_SetCalibrationSelection
  580. * @param OPAMPx OPAMP instance
  581. * @param TransistorsDiffPair This parameter can be one of the following values:
  582. * @arg @ref LL_OPAMP_TRIMMING_NMOS (1)
  583. * @arg @ref LL_OPAMP_TRIMMING_PMOS (1)
  584. * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
  585. * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
  586. *
  587. * (1) Default parameters to be used for calibration
  588. * using two trimming steps (one with each transistors differential
  589. * pair NMOS and PMOS)
  590. * @retval None
  591. */
  592. __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
  593. {
  594. /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */
  595. /* containing other bits reserved for other purpose. */
  596. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, (TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK));
  597. }
  598. /**
  599. * @brief Get OPAMP offset to calibrate the selected transistors
  600. * differential pair NMOS or PMOS.
  601. * @note Preliminarily, OPAMP must be set in mode calibration
  602. * using function @ref LL_OPAMP_SetMode().
  603. * @rmtoll CSR CALSEL LL_OPAMP_GetCalibrationSelection
  604. * @param OPAMPx OPAMP instance
  605. * @retval Returned value can be one of the following values:
  606. * @arg @ref LL_OPAMP_TRIMMING_NMOS (1)
  607. * @arg @ref LL_OPAMP_TRIMMING_PMOS (1)
  608. * @arg @ref LL_OPAMP_TRIMMING_NMOS_VREF_50PC_VDDA
  609. * @arg @ref LL_OPAMP_TRIMMING_PMOS_VREF_3_3PC_VDDA
  610. *
  611. * (1) Default parameters to be used for calibration
  612. * using two trimming steps (one with each transistors differential
  613. * pair NMOS and PMOS)
  614. */
  615. __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
  616. {
  617. uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
  618. return (CalibrationSelection |
  619. (((CalibrationSelection & OPAMP_CSR_CALSEL) == 0UL) ? OPAMP_CSR_TRIMOFFSETN : OPAMP_CSR_TRIMOFFSETP));
  620. }
  621. /**
  622. * @brief Set OPAMP calibration internal reference voltage to output.
  623. * @rmtoll CSR TSTREF LL_OPAMP_SetCalibrationVrefOutput
  624. * @param OPAMPx OPAMP instance
  625. * @param CalibrationVrefOutput This parameter can be one of the following values:
  626. * @arg @ref LL_OPAMP_VREF_OUTPUT_DISABLE
  627. * @arg @ref LL_OPAMP_VREF_OUTPUT_ENABLE
  628. * @retval None
  629. */
  630. __STATIC_INLINE void LL_OPAMP_SetCalibrationVrefOutput(OPAMP_TypeDef *OPAMPx, uint32_t CalibrationVrefOutput)
  631. {
  632. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_TSTREF, CalibrationVrefOutput);
  633. }
  634. /**
  635. * @brief Get OPAMP calibration internal reference voltage to output.
  636. * @rmtoll CSR TSTREF LL_OPAMP_GetCalibrationVrefOutput
  637. * @param OPAMPx OPAMP instance
  638. * @retval Returned value can be one of the following values:
  639. * @arg @ref LL_OPAMP_VREF_OUTPUT_DISABLE
  640. * @arg @ref LL_OPAMP_VREF_OUTPUT_ENABLE
  641. */
  642. __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationVrefOutput(OPAMP_TypeDef *OPAMPx)
  643. {
  644. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_TSTREF));
  645. }
  646. /**
  647. * @brief Get OPAMP calibration result of toggling output.
  648. * @note This functions returns:
  649. * 0 if OPAMP calibration output is reset
  650. * 1 if OPAMP calibration output is set
  651. * @rmtoll CSR OUTCAL LL_OPAMP_IsCalibrationOutputSet
  652. * @param OPAMPx OPAMP instance
  653. * @retval State of bit (1 or 0).
  654. */
  655. __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
  656. {
  657. return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OUTCAL) == OPAMP_CSR_OUTCAL) ? 1UL : 0UL);
  658. }
  659. /**
  660. * @brief Set OPAMP trimming factor for the selected transistors
  661. * differential pair NMOS or PMOS, corresponding to the selected
  662. * power mode.
  663. * @rmtoll CSR TRIMOFFSETN LL_OPAMP_SetTrimmingValue\n
  664. * CSR TRIMOFFSETP LL_OPAMP_SetTrimmingValue
  665. * @param OPAMPx OPAMP instance
  666. * @param TransistorsDiffPair This parameter can be one of the following values:
  667. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  668. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  669. * @param TrimmingValue 0x00...0x1F
  670. * @retval None
  671. */
  672. __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t TransistorsDiffPair, uint32_t TrimmingValue)
  673. {
  674. MODIFY_REG(OPAMPx->CSR,
  675. (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK),
  676. TrimmingValue << ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_CSR_TRIMOFFSETN_Pos : OPAMP_CSR_TRIMOFFSETP_Pos));
  677. }
  678. /**
  679. * @brief Get OPAMP trimming factor for the selected transistors
  680. * differential pair NMOS or PMOS, corresponding to the selected
  681. * power mode.
  682. * @rmtoll CSR TRIMOFFSETN LL_OPAMP_GetTrimmingValue\n
  683. * CSR TRIMOFFSETP LL_OPAMP_GetTrimmingValue
  684. * @param OPAMPx OPAMP instance
  685. * @param TransistorsDiffPair This parameter can be one of the following values:
  686. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  687. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  688. * @retval 0x0...0x1F
  689. */
  690. __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t TransistorsDiffPair)
  691. {
  692. return (uint32_t)(READ_BIT(OPAMPx->CSR, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
  693. >> ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_CSR_TRIMOFFSETN_Pos : OPAMP_CSR_TRIMOFFSETP_Pos));
  694. }
  695. /**
  696. * @}
  697. */
  698. /** @defgroup OPAMP_LL_EF_OPERATION Operation on OPAMP instance
  699. * @{
  700. */
  701. /**
  702. * @brief Enable OPAMP instance.
  703. * @note After enable from off state, OPAMP requires a delay
  704. * to fulfill wake up time specification.
  705. * Refer to device datasheet, parameter "tWAKEUP".
  706. * @rmtoll CSR OPAMPXEN LL_OPAMP_Enable
  707. * @param OPAMPx OPAMP instance
  708. * @retval None
  709. */
  710. __STATIC_INLINE void LL_OPAMP_Enable(OPAMP_TypeDef *OPAMPx)
  711. {
  712. SET_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
  713. }
  714. /**
  715. * @brief Disable OPAMP instance.
  716. * @rmtoll CSR OPAMPXEN LL_OPAMP_Disable
  717. * @param OPAMPx OPAMP instance
  718. * @retval None
  719. */
  720. __STATIC_INLINE void LL_OPAMP_Disable(OPAMP_TypeDef *OPAMPx)
  721. {
  722. CLEAR_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN);
  723. }
  724. /**
  725. * @brief Get OPAMP instance enable state
  726. * (0: OPAMP is disabled, 1: OPAMP is enabled)
  727. * @rmtoll CSR OPAMPXEN LL_OPAMP_IsEnabled
  728. * @param OPAMPx OPAMP instance
  729. * @retval State of bit (1 or 0).
  730. */
  731. __STATIC_INLINE uint32_t LL_OPAMP_IsEnabled(OPAMP_TypeDef *OPAMPx)
  732. {
  733. return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMPxEN) == (OPAMP_CSR_OPAMPxEN)) ? 1UL : 0UL);
  734. }
  735. /**
  736. * @brief Lock OPAMP instance.
  737. * @note Once locked, OPAMP configuration can be accessed in read-only.
  738. * @note The only way to unlock the OPAMP is a device hardware reset.
  739. * @rmtoll CSR LOCK LL_OPAMP_Lock
  740. * @param OPAMPx OPAMP instance
  741. * @retval None
  742. */
  743. __STATIC_INLINE void LL_OPAMP_Lock(OPAMP_TypeDef *OPAMPx)
  744. {
  745. SET_BIT(OPAMPx->CSR, OPAMP_CSR_LOCK);
  746. }
  747. /**
  748. * @brief Get OPAMP lock state
  749. * (0: OPAMP is unlocked, 1: OPAMP is locked).
  750. * @note Once locked, OPAMP configuration can be accessed in read-only.
  751. * @note The only way to unlock the OPAMP is a device hardware reset.
  752. * @rmtoll CSR LOCK LL_OPAMP_IsLocked
  753. * @param OPAMPx OPAMP instance
  754. * @retval State of bit (1 or 0).
  755. */
  756. __STATIC_INLINE uint32_t LL_OPAMP_IsLocked(OPAMP_TypeDef *OPAMPx)
  757. {
  758. return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_LOCK) == (OPAMP_CSR_LOCK)) ? 1UL : 0UL);
  759. }
  760. /**
  761. * @}
  762. */
  763. #if defined(USE_FULL_LL_DRIVER)
  764. /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
  765. * @{
  766. */
  767. ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
  768. ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  769. void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  770. /**
  771. * @}
  772. */
  773. #endif /* USE_FULL_LL_DRIVER */
  774. /**
  775. * @}
  776. */
  777. /**
  778. * @}
  779. */
  780. #endif /* OPAMP1 || OPAMP2 || OPAMP3 || OPAMP4 */
  781. /**
  782. * @}
  783. */
  784. #ifdef __cplusplus
  785. }
  786. #endif
  787. #endif /* STM32F3xx_LL_OPAMP_H */