stm32l4xx_ll_opamp.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_opamp.h
  4. * @author MCD Application Team
  5. * @brief Header file of OPAMP LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 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 STM32L4xx_LL_OPAMP_H
  20. #define STM32L4xx_LL_OPAMP_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l4xx.h"
  26. /** @addtogroup STM32L4xx_LL_Driver
  27. * @{
  28. */
  29. #if defined (OPAMP1) || defined (OPAMP2)
  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 power mode: */
  40. /* To select into literal LL_OPAMP_POWERMODE_x the relevant bits for: */
  41. /* - OPAMP power mode into control register */
  42. /* - OPAMP trimming register offset */
  43. /* Internal register offset for OPAMP trimming configuration */
  44. #define OPAMP_POWERMODE_OTR_REGOFFSET 0x00000000U
  45. #define OPAMP_POWERMODE_LPOTR_REGOFFSET 0x00000001U
  46. #define OPAMP_POWERMODE_OTR_REGOFFSET_MASK (OPAMP_POWERMODE_OTR_REGOFFSET | OPAMP_POWERMODE_LPOTR_REGOFFSET)
  47. /* Mask for OPAMP power mode into control register */
  48. #define OPAMP_POWERMODE_CSR_BIT_MASK (OPAMP_CSR_OPALPM)
  49. /* Internal mask for OPAMP trimming of transistors differential pair NMOS */
  50. /* or PMOS. */
  51. /* To select into literal LL_OPAMP_TRIMMING_x the relevant bits for: */
  52. /* - OPAMP trimming selection of transistors differential pair */
  53. /* - OPAMP trimming values of transistors differential pair */
  54. #define OPAMP_TRIMMING_SELECT_MASK (OPAMP1_CSR_CALSEL)
  55. #define OPAMP_TRIMMING_VALUE_MASK (OPAMP_OTR_TRIMOFFSETP | OPAMP_OTR_TRIMOFFSETN)
  56. /**
  57. * @}
  58. */
  59. /* Private macros ------------------------------------------------------------*/
  60. /** @defgroup OPAMP_LL_Private_Macros OPAMP Private Macros
  61. * @{
  62. */
  63. /**
  64. * @brief Driver macro reserved for internal use: set a pointer to
  65. * a register from a register basis from which an offset
  66. * is applied.
  67. * @param __REG__ Register basis from which the offset is applied.
  68. * @param __REG_OFFSET__ Offset to be applied (unit: number of registers).
  69. * @retval Register address
  70. */
  71. #define __OPAMP_PTR_REG_OFFSET(__REG__, __REG_OFFSET__) \
  72. ((uint32_t *)((uint32_t) ((uint32_t)(&(__REG__)) + ((__REG_OFFSET__) << 2U))))
  73. /**
  74. * @}
  75. */
  76. /* Exported types ------------------------------------------------------------*/
  77. #if defined(USE_FULL_LL_DRIVER)
  78. /** @defgroup OPAMP_LL_ES_INIT OPAMP Exported Init structure
  79. * @{
  80. */
  81. /**
  82. * @brief Structure definition of some features of OPAMP instance.
  83. */
  84. typedef struct
  85. {
  86. uint32_t PowerMode; /*!< Set OPAMP power mode.
  87. This parameter can be a value of @ref OPAMP_LL_EC_POWERMODE
  88. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetPowerMode(). */
  89. uint32_t FunctionalMode; /*!< Set OPAMP functional mode by setting internal connections: OPAMP operation in standalone, follower, ...
  90. This parameter can be a value of @ref OPAMP_LL_EC_FUNCTIONAL_MODE
  91. @note If OPAMP is configured in mode PGA, the gain can be configured using function @ref LL_OPAMP_SetPGAGain().
  92. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetFunctionalMode(). */
  93. uint32_t InputNonInverting; /*!< Set OPAMP input non-inverting connection.
  94. This parameter can be a value of @ref OPAMP_LL_EC_INPUT_NONINVERTING
  95. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputNonInverting(). */
  96. uint32_t InputInverting; /*!< Set OPAMP inverting input connection.
  97. This parameter can be a value of @ref OPAMP_LL_EC_INPUT_INVERTING
  98. @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.
  99. This feature can be modified afterwards using unitary function @ref LL_OPAMP_SetInputInverting(). */
  100. } LL_OPAMP_InitTypeDef;
  101. /**
  102. * @}
  103. */
  104. #endif /* USE_FULL_LL_DRIVER */
  105. /* Exported constants --------------------------------------------------------*/
  106. /** @defgroup OPAMP_LL_Exported_Constants OPAMP Exported Constants
  107. * @{
  108. */
  109. /** @defgroup OPAMP_LL_EC_POWERSUPPLY_RANGE OPAMP power supply range
  110. * @{
  111. */
  112. #define LL_OPAMP_POWERSUPPLY_RANGE_LOW 0x00000000U /*!< Power supply range low. On STM32L4 series: Vdda lower than 2.4V. */
  113. #define LL_OPAMP_POWERSUPPLY_RANGE_HIGH (OPAMP1_CSR_OPARANGE) /*!< Power supply range high. On STM32L4 series: Vdda higher than 2.4V. */
  114. /**
  115. * @}
  116. */
  117. /** @defgroup OPAMP_LL_EC_POWERMODE OPAMP power mode
  118. * @{
  119. */
  120. #define LL_OPAMP_POWERMODE_NORMALPOWER (OPAMP_POWERMODE_OTR_REGOFFSET) /*!< OPAMP power mode normal */
  121. #define LL_OPAMP_POWERMODE_LOWPOWER (OPAMP_POWERMODE_LPOTR_REGOFFSET | OPAMP_CSR_OPALPM) /*!< OPAMP power mode low-power */
  122. #define LL_OPAMP_POWERMODE_NORMAL LL_OPAMP_POWERMODE_NORMALPOWER /*!< OPAMP power mode normal - Old Naming for compatibility */
  123. /**
  124. * @}
  125. */
  126. /** @defgroup OPAMP_LL_EC_MODE OPAMP mode calibration or functional.
  127. * @{
  128. */
  129. #define LL_OPAMP_MODE_FUNCTIONAL 0x00000000U /*!< OPAMP functional mode */
  130. #define LL_OPAMP_MODE_CALIBRATION (OPAMP_CSR_CALON) /*!< OPAMP calibration mode */
  131. /**
  132. * @}
  133. */
  134. /** @defgroup OPAMP_LL_EC_FUNCTIONAL_MODE OPAMP functional mode
  135. * @{
  136. */
  137. #define LL_OPAMP_MODE_STANDALONE 0x00000000U /*!< OPAMP functional mode, OPAMP operation in standalone */
  138. #define LL_OPAMP_MODE_FOLLOWER (OPAMP_CSR_OPAMODE_1 | OPAMP_CSR_OPAMODE_0) /*!< OPAMP functional mode, OPAMP operation in follower */
  139. #define LL_OPAMP_MODE_PGA (OPAMP_CSR_OPAMODE_1) /*!< OPAMP functional mode, OPAMP operation in PGA */
  140. /**
  141. * @}
  142. */
  143. /** @defgroup OPAMP_LL_EC_MODE_PGA_GAIN OPAMP PGA gain (relevant when OPAMP is in functional mode PGA)
  144. * @{
  145. */
  146. #define LL_OPAMP_PGA_GAIN_2 0x00000000U /*!< OPAMP PGA gain 2 */
  147. #define LL_OPAMP_PGA_GAIN_4 (OPAMP_CSR_PGGAIN_0) /*!< OPAMP PGA gain 4 */
  148. #define LL_OPAMP_PGA_GAIN_8 (OPAMP_CSR_PGGAIN_1) /*!< OPAMP PGA gain 8 */
  149. #define LL_OPAMP_PGA_GAIN_16 (OPAMP_CSR_PGGAIN_1 | OPAMP_CSR_PGGAIN_0 ) /*!< OPAMP PGA gain 16 */
  150. /**
  151. * @}
  152. */
  153. /** @defgroup OPAMP_LL_EC_INPUT_NONINVERTING OPAMP input non-inverting
  154. * @{
  155. */
  156. #define LL_OPAMP_INPUT_NONINVERT_IO0 0x00000000U /*!< OPAMP non inverting input connected to GPIO pin (pin PA0 for OPAMP1, pin PA6 for OPAMP2) */
  157. #define LL_OPAMP_INPUT_NONINV_DAC1_CH1 (OPAMP1_CSR_VPSEL) /*!< OPAMP non inverting input connected to DAC1 channel1 output */
  158. /**
  159. * @}
  160. */
  161. /** @defgroup OPAMP_LL_EC_INPUT_INVERTING OPAMP input inverting
  162. * @{
  163. */
  164. #define LL_OPAMP_INPUT_INVERT_IO0 0x00000000U /*!< OPAMP inverting input connected to GPIO pin (valid also in PGA mode for filtering). 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). */
  165. #define LL_OPAMP_INPUT_INVERT_IO1 (OPAMP_CSR_VMSEL_0) /*!< OPAMP inverting input (low leakage input) connected to GPIO pin (available only on package BGA132). 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). */
  166. #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) */
  167. /**
  168. * @}
  169. */
  170. /** @defgroup OPAMP_LL_EC_INPUT_LEGACY OPAMP inputs legacy literals name
  171. * @{
  172. */
  173. #define LL_OPAMP_NONINVERTINGINPUT_IO0 LL_OPAMP_INPUT_NONINVERT_IO0
  174. #define LL_OPAMP_NONINVERTINGINPUT_DAC_CH LL_OPAMP_INPUT_NONINV_DAC1_CH1
  175. #define LL_OPAMP_INVERTINGINPUT_IO0 LL_OPAMP_INPUT_INVERT_IO0
  176. #define LL_OPAMP_INVERTINGINPUT_IO1 LL_OPAMP_INPUT_INVERT_IO1
  177. #define LL_OPAMP_INVERTINGINPUT_CONNECT_NO LL_OPAMP_INPUT_INVERT_CONNECT_NO
  178. #define LL_OPAMP_INPUT_NONINVERT_DAC1_CH1 LL_OPAMP_INPUT_NONINV_DAC1_CH1
  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 (OPAMP_OTR_TRIMOFFSETN) /*!< OPAMP trimming of transistors differential pair NMOS */
  194. #define LL_OPAMP_TRIMMING_PMOS (OPAMP_OTR_TRIMOFFSETP | OPAMP1_CSR_CALSEL) /*!< OPAMP trimming of transistors differential pair PMOS */
  195. /**
  196. * @}
  197. */
  198. /** @defgroup OPAMP_LL_EC_HW_DELAYS Definitions of OPAMP hardware constraints delays
  199. * @note Only OPAMP peripheral HW delays are defined in OPAMP LL driver driver,
  200. * not timeout values.
  201. * For details on delays values, refer to descriptions in source code
  202. * above each literal definition.
  203. * @{
  204. */
  205. /* Delay for OPAMP startup time (transition from state disable to enable). */
  206. /* Note: OPAMP startup time depends on board application environment: */
  207. /* impedance connected to OPAMP output. */
  208. /* The delay below is specified under conditions: */
  209. /* - OPAMP in mode low power */
  210. /* - OPAMP in functional mode follower */
  211. /* - load impedance of 4kOhm (min), 50pF (max) */
  212. /* Literal set to maximum value (refer to device datasheet, */
  213. /* parameter "tWAKEUP"). */
  214. /* Unit: us */
  215. #define LL_OPAMP_DELAY_STARTUP_US ((uint32_t) 30U) /*!< Delay for OPAMP startup time */
  216. /**
  217. * @}
  218. */
  219. /**
  220. * @}
  221. */
  222. /* Exported macro ------------------------------------------------------------*/
  223. /** @defgroup OPAMP_LL_Exported_Macros OPAMP Exported Macros
  224. * @{
  225. */
  226. /** @defgroup OPAMP_LL_EM_WRITE_READ Common write and read registers macro
  227. * @{
  228. */
  229. /**
  230. * @brief Write a value in OPAMP register
  231. * @param __INSTANCE__ OPAMP Instance
  232. * @param __REG__ Register to be written
  233. * @param __VALUE__ Value to be written in the register
  234. * @retval None
  235. */
  236. #define LL_OPAMP_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG((__INSTANCE__)->__REG__, (__VALUE__))
  237. /**
  238. * @brief Read a value in OPAMP register
  239. * @param __INSTANCE__ OPAMP Instance
  240. * @param __REG__ Register to be read
  241. * @retval Register value
  242. */
  243. #define LL_OPAMP_ReadReg(__INSTANCE__, __REG__) READ_REG((__INSTANCE__)->__REG__)
  244. /**
  245. * @}
  246. */
  247. /** @defgroup OPAMP_LL_EM_HELPER_MACRO OPAMP helper macro
  248. * @{
  249. */
  250. /**
  251. * @brief Helper macro to select the OPAMP common instance
  252. * to which is belonging the selected OPAMP instance.
  253. * @note OPAMP common register instance can be used to
  254. * set parameters common to several OPAMP instances.
  255. * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
  256. * @param __OPAMPx__ OPAMP instance
  257. * @retval OPAMP common instance
  258. */
  259. #if defined(OPAMP1) && defined(OPAMP2)
  260. #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \
  261. (OPAMP12_COMMON)
  262. #else
  263. #define __LL_OPAMP_COMMON_INSTANCE(__OPAMPx__) \
  264. (OPAMP1_COMMON)
  265. #endif
  266. /**
  267. * @brief Helper macro to check if all OPAMP instances sharing the same
  268. * OPAMP common instance are disabled.
  269. * @note This check is required by functions with setting conditioned to
  270. * OPAMP state:
  271. * All OPAMP instances of the OPAMP common group must be disabled.
  272. * Refer to functions having argument "OPAMPxy_COMMON" as parameter.
  273. * @retval 0: All OPAMP instances sharing the same OPAMP common instance
  274. * are disabled.
  275. * 1: At least one OPAMP instance sharing the same OPAMP common instance
  276. * is enabled
  277. */
  278. #if defined(OPAMP1) && defined(OPAMP2)
  279. #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \
  280. (LL_OPAMP_IsEnabled(OPAMP1) | \
  281. LL_OPAMP_IsEnabled(OPAMP2) )
  282. #else
  283. #define __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE() \
  284. (LL_OPAMP_IsEnabled(OPAMP1))
  285. #endif
  286. /**
  287. * @}
  288. */
  289. /**
  290. * @}
  291. */
  292. /* Exported functions --------------------------------------------------------*/
  293. /** @defgroup OPAMP_LL_Exported_Functions OPAMP Exported Functions
  294. * @{
  295. */
  296. /** @defgroup OPAMP_LL_EF_Configuration_opamp_common Configuration of OPAMP hierarchical scope: common to several OPAMP instances
  297. * @{
  298. */
  299. /**
  300. * @brief Set OPAMP power range.
  301. * @note The OPAMP power range applies to several OPAMP instances
  302. * (if several OPAMP instances available on the selected device).
  303. * @note On this STM32 series, setting of this feature is conditioned to
  304. * OPAMP state:
  305. * All OPAMP instances of the OPAMP common group must be disabled.
  306. * This check can be done with function @ref LL_OPAMP_IsEnabled() for each
  307. * OPAMP instance or by using helper macro
  308. * @ref __LL_OPAMP_IS_ENABLED_ALL_COMMON_INSTANCE().
  309. * @rmtoll CSR OPARANGE LL_OPAMP_SetCommonPowerRange
  310. * @param OPAMPxy_COMMON OPAMP common instance
  311. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
  312. * @param PowerRange This parameter can be one of the following values:
  313. * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
  314. * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
  315. * @retval None
  316. */
  317. __STATIC_INLINE void LL_OPAMP_SetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON, uint32_t PowerRange)
  318. {
  319. /* Prevent unused parameter warning */
  320. (void)(*OPAMPxy_COMMON);
  321. MODIFY_REG(OPAMP1->CSR, OPAMP1_CSR_OPARANGE, PowerRange);
  322. }
  323. /**
  324. * @brief Get OPAMP power range.
  325. * @note The OPAMP power range applies to several OPAMP instances
  326. * (if several OPAMP instances available on the selected device).
  327. * @rmtoll CSR OPARANGE LL_OPAMP_GetCommonPowerRange
  328. * @param OPAMPxy_COMMON OPAMP common instance
  329. * (can be set directly from CMSIS definition or by using helper macro @ref __LL_OPAMP_COMMON_INSTANCE() )
  330. * @retval Returned value can be one of the following values:
  331. * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_LOW
  332. * @arg @ref LL_OPAMP_POWERSUPPLY_RANGE_HIGH
  333. */
  334. __STATIC_INLINE uint32_t LL_OPAMP_GetCommonPowerRange(OPAMP_Common_TypeDef *OPAMPxy_COMMON)
  335. {
  336. /* Prevent unused parameter warning */
  337. (void)(*OPAMPxy_COMMON);
  338. return (uint32_t)(READ_BIT(OPAMP1->CSR, OPAMP1_CSR_OPARANGE));
  339. }
  340. /**
  341. * @}
  342. */
  343. /** @defgroup OPAMP_LL_EF_CONFIGURATION_OPAMP_INSTANCE Configuration of OPAMP hierarchical scope: OPAMP instance
  344. * @{
  345. */
  346. /**
  347. * @brief Set OPAMP power mode.
  348. * @note The OPAMP must be disabled to change this configuration.
  349. * @rmtoll CSR OPALPM LL_OPAMP_SetPowerMode
  350. * @param OPAMPx OPAMP instance
  351. * @param PowerMode This parameter can be one of the following values:
  352. * @arg @ref LL_OPAMP_POWERMODE_NORMALPOWER
  353. * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  354. * @retval None
  355. */
  356. __STATIC_INLINE void LL_OPAMP_SetPowerMode(OPAMP_TypeDef *OPAMPx, uint32_t PowerMode)
  357. {
  358. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPALPM, (PowerMode & OPAMP_POWERMODE_CSR_BIT_MASK));
  359. }
  360. /**
  361. * @brief Get OPAMP power mode.
  362. * @rmtoll CSR OPALPM LL_OPAMP_GetPowerMode
  363. * @param OPAMPx OPAMP instance
  364. * @retval Returned value can be one of the following values:
  365. * @arg @ref LL_OPAMP_POWERMODE_NORMALPOWER
  366. * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  367. */
  368. __STATIC_INLINE uint32_t LL_OPAMP_GetPowerMode(OPAMP_TypeDef *OPAMPx)
  369. {
  370. uint32_t power_mode = (READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPALPM));
  371. return (uint32_t)(power_mode | (power_mode >> (OPAMP_CSR_OPALPM_Pos)));
  372. }
  373. /**
  374. * @brief Set OPAMP mode calibration or functional.
  375. * @note OPAMP mode corresponds to functional or calibration mode:
  376. * - functional mode: OPAMP operation in standalone, follower, ...
  377. * Set functional mode using function
  378. * @ref LL_OPAMP_SetFunctionalMode().
  379. * - calibration mode: offset calibration of the selected
  380. * transistors differential pair NMOS or PMOS.
  381. * @note On this STM32 series, during calibration, OPAMP functional
  382. * mode must be set to standalone or follower mode
  383. * (in order to open internal connections to resistors
  384. * of PGA mode).
  385. * Refer to function @ref LL_OPAMP_SetFunctionalMode().
  386. * @rmtoll CSR CALON LL_OPAMP_SetMode
  387. * @param OPAMPx OPAMP instance
  388. * @param Mode This parameter can be one of the following values:
  389. * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  390. * @arg @ref LL_OPAMP_MODE_CALIBRATION
  391. * @retval None
  392. */
  393. __STATIC_INLINE void LL_OPAMP_SetMode(OPAMP_TypeDef *OPAMPx, uint32_t Mode)
  394. {
  395. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALON, Mode);
  396. }
  397. /**
  398. * @brief Get OPAMP mode calibration or functional.
  399. * @note OPAMP mode corresponds to functional or calibration mode:
  400. * - functional mode: OPAMP operation in standalone, follower, ...
  401. * Set functional mode using function
  402. * @ref LL_OPAMP_SetFunctionalMode().
  403. * - calibration mode: offset calibration of the selected
  404. * transistors differential pair NMOS or PMOS.
  405. * @rmtoll CSR CALON LL_OPAMP_GetMode
  406. * @param OPAMPx OPAMP instance
  407. * @retval Returned value can be one of the following values:
  408. * @arg @ref LL_OPAMP_MODE_FUNCTIONAL
  409. * @arg @ref LL_OPAMP_MODE_CALIBRATION
  410. */
  411. __STATIC_INLINE uint32_t LL_OPAMP_GetMode(OPAMP_TypeDef *OPAMPx)
  412. {
  413. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALON));
  414. }
  415. /**
  416. * @brief Set OPAMP functional mode by setting internal connections.
  417. * OPAMP operation in standalone, follower, ...
  418. * @note This function reset bit of calibration mode to ensure
  419. * to be in functional mode, in order to have OPAMP parameters
  420. * (inputs selection, ...) set with the corresponding OPAMP mode
  421. * to be effective.
  422. * @rmtoll CSR OPAMODE LL_OPAMP_SetFunctionalMode
  423. * @param OPAMPx OPAMP instance
  424. * @param FunctionalMode This parameter can be one of the following values:
  425. * @arg @ref LL_OPAMP_MODE_STANDALONE
  426. * @arg @ref LL_OPAMP_MODE_FOLLOWER
  427. * @arg @ref LL_OPAMP_MODE_PGA
  428. * @retval None
  429. */
  430. __STATIC_INLINE void LL_OPAMP_SetFunctionalMode(OPAMP_TypeDef *OPAMPx, uint32_t FunctionalMode)
  431. {
  432. /* Note: Bit OPAMP_CSR_CALON reset to ensure to be in functional mode */
  433. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_OPAMODE | OPAMP_CSR_CALON, FunctionalMode);
  434. }
  435. /**
  436. * @brief Get OPAMP functional mode from setting of internal connections.
  437. * OPAMP operation in standalone, follower, ...
  438. * @rmtoll CSR OPAMODE LL_OPAMP_GetFunctionalMode
  439. * @param OPAMPx OPAMP instance
  440. * @retval Returned value can be one of the following values:
  441. * @arg @ref LL_OPAMP_MODE_STANDALONE
  442. * @arg @ref LL_OPAMP_MODE_FOLLOWER
  443. * @arg @ref LL_OPAMP_MODE_PGA
  444. */
  445. __STATIC_INLINE uint32_t LL_OPAMP_GetFunctionalMode(OPAMP_TypeDef *OPAMPx)
  446. {
  447. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_OPAMODE));
  448. }
  449. /**
  450. * @brief Set OPAMP PGA gain.
  451. * @note Preliminarily, OPAMP must be set in mode PGA
  452. * using function @ref LL_OPAMP_SetFunctionalMode().
  453. * @rmtoll CSR PGGAIN LL_OPAMP_SetPGAGain
  454. * @param OPAMPx OPAMP instance
  455. * @param PGAGain This parameter can be one of the following values:
  456. * @arg @ref LL_OPAMP_PGA_GAIN_2
  457. * @arg @ref LL_OPAMP_PGA_GAIN_4
  458. * @arg @ref LL_OPAMP_PGA_GAIN_8
  459. * @arg @ref LL_OPAMP_PGA_GAIN_16
  460. * @retval None
  461. */
  462. __STATIC_INLINE void LL_OPAMP_SetPGAGain(OPAMP_TypeDef *OPAMPx, uint32_t PGAGain)
  463. {
  464. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_PGGAIN, PGAGain);
  465. }
  466. /**
  467. * @brief Get OPAMP PGA gain.
  468. * @note Preliminarily, OPAMP must be set in mode PGA
  469. * using function @ref LL_OPAMP_SetFunctionalMode().
  470. * @rmtoll CSR PGGAIN LL_OPAMP_GetPGAGain
  471. * @param OPAMPx OPAMP instance
  472. * @retval Returned value can be one of the following values:
  473. * @arg @ref LL_OPAMP_PGA_GAIN_2
  474. * @arg @ref LL_OPAMP_PGA_GAIN_4
  475. * @arg @ref LL_OPAMP_PGA_GAIN_8
  476. * @arg @ref LL_OPAMP_PGA_GAIN_16
  477. */
  478. __STATIC_INLINE uint32_t LL_OPAMP_GetPGAGain(OPAMP_TypeDef *OPAMPx)
  479. {
  480. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_PGGAIN));
  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_NONINV_DAC1_CH1
  495. * @retval None
  496. */
  497. __STATIC_INLINE void LL_OPAMP_SetInputNonInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputNonInverting)
  498. {
  499. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VPSEL, InputNonInverting);
  500. }
  501. /**
  502. * @brief Get OPAMP non-inverting input connection.
  503. * @rmtoll CSR VPSEL LL_OPAMP_GetInputNonInverting
  504. * @param OPAMPx OPAMP instance
  505. * @retval Returned value can be one of the following values:
  506. * @arg @ref LL_OPAMP_INPUT_NONINVERT_IO0
  507. * @arg @ref LL_OPAMP_INPUT_NONINV_DAC1_CH1
  508. */
  509. __STATIC_INLINE uint32_t LL_OPAMP_GetInputNonInverting(OPAMP_TypeDef *OPAMPx)
  510. {
  511. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VPSEL));
  512. }
  513. /**
  514. * @brief Set OPAMP inverting input connection.
  515. * @note OPAMP inverting input is used with OPAMP in mode standalone
  516. * or PGA with external capacitors for filtering circuit.
  517. * Otherwise (OPAMP in mode follower), OPAMP inverting input
  518. * is not used (not connected to GPIO pin).
  519. * @rmtoll CSR VMSEL LL_OPAMP_SetInputInverting
  520. * @param OPAMPx OPAMP instance
  521. * @param InputInverting This parameter can be one of the following values:
  522. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  523. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
  524. * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  525. * @retval None
  526. */
  527. __STATIC_INLINE void LL_OPAMP_SetInputInverting(OPAMP_TypeDef *OPAMPx, uint32_t InputInverting)
  528. {
  529. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_VMSEL, InputInverting);
  530. }
  531. /**
  532. * @brief Get OPAMP inverting input connection.
  533. * @rmtoll CSR VMSEL LL_OPAMP_GetInputInverting
  534. * @param OPAMPx OPAMP instance
  535. * @retval Returned value can be one of the following values:
  536. * @arg @ref LL_OPAMP_INPUT_INVERT_IO0
  537. * @arg @ref LL_OPAMP_INPUT_INVERT_IO1
  538. * @arg @ref LL_OPAMP_INPUT_INVERT_CONNECT_NO
  539. */
  540. __STATIC_INLINE uint32_t LL_OPAMP_GetInputInverting(OPAMP_TypeDef *OPAMPx)
  541. {
  542. return (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_VMSEL));
  543. }
  544. /**
  545. * @}
  546. */
  547. /** @defgroup OPAMP_LL_EF_Configuration_Legacy_Functions Configuration of OPAMP, legacy functions name
  548. * @{
  549. */
  550. /* Old functions name kept for legacy purpose, to be replaced by the */
  551. /* current functions name. */
  552. __STATIC_INLINE void LL_OPAMP_SetNonInvertingInput(OPAMP_TypeDef *OPAMPx, uint32_t NonInvertingInput)
  553. {
  554. LL_OPAMP_SetInputNonInverting(OPAMPx, NonInvertingInput);
  555. }
  556. __STATIC_INLINE void LL_OPAMP_SetInvertingInput(OPAMP_TypeDef *OPAMPx, uint32_t InvertingInput)
  557. {
  558. LL_OPAMP_SetInputInverting(OPAMPx, InvertingInput);
  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
  600. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  601. * @retval None
  602. */
  603. __STATIC_INLINE void LL_OPAMP_SetCalibrationSelection(OPAMP_TypeDef *OPAMPx, uint32_t TransistorsDiffPair)
  604. {
  605. /* Parameter used with mask "OPAMP_TRIMMING_SELECT_MASK" because */
  606. /* containing other bits reserved for other purpose. */
  607. MODIFY_REG(OPAMPx->CSR, OPAMP_CSR_CALSEL, (TransistorsDiffPair & OPAMP_TRIMMING_SELECT_MASK));
  608. }
  609. /**
  610. * @brief Get OPAMP offset to calibrate the selected transistors
  611. * differential pair NMOS or PMOS.
  612. * @note Preliminarily, OPAMP must be set in mode calibration
  613. * using function @ref LL_OPAMP_SetMode().
  614. * @rmtoll CSR CALSEL LL_OPAMP_GetCalibrationSelection
  615. * @param OPAMPx OPAMP instance
  616. * @retval Returned value can be one of the following values:
  617. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  618. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  619. */
  620. __STATIC_INLINE uint32_t LL_OPAMP_GetCalibrationSelection(OPAMP_TypeDef *OPAMPx)
  621. {
  622. uint32_t CalibrationSelection = (uint32_t)(READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALSEL));
  623. return (CalibrationSelection |
  624. (((CalibrationSelection & OPAMP_CSR_CALSEL) == 0UL) ? OPAMP_OTR_TRIMOFFSETN : OPAMP_OTR_TRIMOFFSETP));
  625. }
  626. /**
  627. * @brief Get OPAMP calibration result of toggling output.
  628. * @note This functions returns:
  629. * 0 if OPAMP calibration output is reset
  630. * 1 if OPAMP calibration output is set
  631. * @rmtoll CSR CALOUT LL_OPAMP_IsCalibrationOutputSet
  632. * @param OPAMPx OPAMP instance
  633. * @retval State of bit (1 or 0).
  634. */
  635. __STATIC_INLINE uint32_t LL_OPAMP_IsCalibrationOutputSet(OPAMP_TypeDef *OPAMPx)
  636. {
  637. return ((READ_BIT(OPAMPx->CSR, OPAMP_CSR_CALOUT) == OPAMP_CSR_CALOUT) ? 1UL : 0UL);
  638. }
  639. /**
  640. * @brief Set OPAMP trimming factor for the selected transistors
  641. * differential pair NMOS or PMOS, corresponding to the selected
  642. * power mode.
  643. * @rmtoll OTR TRIMOFFSETN LL_OPAMP_SetTrimmingValue\n
  644. * OTR TRIMOFFSETP LL_OPAMP_SetTrimmingValue\n
  645. * LPOTR TRIMLPOFFSETN LL_OPAMP_SetTrimmingValue\n
  646. * LPOTR TRIMLPOFFSETP LL_OPAMP_SetTrimmingValue
  647. * @param OPAMPx OPAMP instance
  648. * @param PowerMode This parameter can be one of the following values:
  649. * @arg @ref LL_OPAMP_POWERMODE_NORMALPOWER
  650. * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  651. * @param TransistorsDiffPair This parameter can be one of the following values:
  652. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  653. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  654. * @param TrimmingValue 0x00...0x1F
  655. * @retval None
  656. */
  657. __STATIC_INLINE void LL_OPAMP_SetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair, uint32_t TrimmingValue)
  658. {
  659. __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
  660. /* Set bits with position in register depending on parameter */
  661. /* "TransistorsDiffPair". */
  662. /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
  663. /* containing other bits reserved for other purpose. */
  664. MODIFY_REG(*preg,
  665. (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK),
  666. TrimmingValue << ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_TRIMOFFSETP_Pos));
  667. }
  668. /**
  669. * @brief Get OPAMP trimming factor for the selected transistors
  670. * differential pair NMOS or PMOS, corresponding to the selected
  671. * power mode.
  672. * @rmtoll OTR TRIMOFFSETN LL_OPAMP_GetTrimmingValue\n
  673. * OTR TRIMOFFSETP LL_OPAMP_GetTrimmingValue\n
  674. * LPOTR TRIMLPOFFSETN LL_OPAMP_GetTrimmingValue\n
  675. * LPOTR TRIMLPOFFSETP LL_OPAMP_GetTrimmingValue
  676. * @param OPAMPx OPAMP instance
  677. * @param PowerMode This parameter can be one of the following values:
  678. * @arg @ref LL_OPAMP_POWERMODE_NORMALPOWER
  679. * @arg @ref LL_OPAMP_POWERMODE_LOWPOWER
  680. * @param TransistorsDiffPair This parameter can be one of the following values:
  681. * @arg @ref LL_OPAMP_TRIMMING_NMOS
  682. * @arg @ref LL_OPAMP_TRIMMING_PMOS
  683. * @retval 0x0...0x1F
  684. */
  685. __STATIC_INLINE uint32_t LL_OPAMP_GetTrimmingValue(OPAMP_TypeDef* OPAMPx, uint32_t PowerMode, uint32_t TransistorsDiffPair)
  686. {
  687. const __IO uint32_t *preg = __OPAMP_PTR_REG_OFFSET(OPAMPx->OTR, (PowerMode & OPAMP_POWERMODE_OTR_REGOFFSET_MASK));
  688. /* Retrieve bits with position in register depending on parameter */
  689. /* "TransistorsDiffPair". */
  690. /* Parameter used with mask "OPAMP_TRIMMING_VALUE_MASK" because */
  691. /* containing other bits reserved for other purpose. */
  692. return (uint32_t)(READ_BIT(*preg, (TransistorsDiffPair & OPAMP_TRIMMING_VALUE_MASK))
  693. >> ((TransistorsDiffPair == LL_OPAMP_TRIMMING_NMOS) ? OPAMP_OTR_TRIMOFFSETN_Pos : OPAMP_OTR_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. * @}
  737. */
  738. #if defined(USE_FULL_LL_DRIVER)
  739. /** @defgroup OPAMP_LL_EF_Init Initialization and de-initialization functions
  740. * @{
  741. */
  742. ErrorStatus LL_OPAMP_DeInit(OPAMP_TypeDef *OPAMPx);
  743. ErrorStatus LL_OPAMP_Init(OPAMP_TypeDef *OPAMPx, LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  744. void LL_OPAMP_StructInit(LL_OPAMP_InitTypeDef *OPAMP_InitStruct);
  745. /**
  746. * @}
  747. */
  748. #endif /* USE_FULL_LL_DRIVER */
  749. /**
  750. * @}
  751. */
  752. /**
  753. * @}
  754. */
  755. #endif /* OPAMP1 || OPAMP2 */
  756. /**
  757. * @}
  758. */
  759. #ifdef __cplusplus
  760. }
  761. #endif
  762. #endif /* STM32L4xx_LL_OPAMP_H */