stm32f3xx_ll_opamp.h 41 KB

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