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

140 lines
4.7 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_hal_comp_ex.c
  4. * @author MCD Application Team
  5. * @brief Extended COMP HAL module driver.
  6. * @brief This file provides firmware functions to manage voltage reference
  7. * VrefInt that must be specifically controled for comparator
  8. * instance COMP2.
  9. @verbatim
  10. ==============================================================================
  11. ##### COMP peripheral Extended features #####
  12. ==============================================================================
  13. [..] Comparing to other previous devices, the COMP interface for STM32L0XX
  14. devices contains the following additional features
  15. (+) Possibility to enable or disable the VREFINT which is used as input
  16. to the comparator.
  17. @endverbatim
  18. ******************************************************************************
  19. * @attention
  20. *
  21. * <h2><center>&copy; Copyright(c) 2016 STMicroelectronics.
  22. * All rights reserved.</center></h2>
  23. *
  24. * This software component is licensed by ST under BSD 3-Clause license,
  25. * the "License"; You may not use this file except in compliance with the
  26. * License. You may obtain a copy of the License at:
  27. * opensource.org/licenses/BSD-3-Clause
  28. *
  29. ******************************************************************************
  30. */
  31. #if !defined (STM32L010xB) && !defined (STM32L010x8) && !defined (STM32L010x6) && !defined (STM32L010x4)
  32. /* Includes ------------------------------------------------------------------*/
  33. #include "stm32l0xx_hal.h"
  34. /** @addtogroup STM32L0xx_HAL_Driver
  35. * @{
  36. */
  37. #ifdef HAL_COMP_MODULE_ENABLED
  38. /** @addtogroup COMPEx
  39. * @brief Extended COMP HAL module driver
  40. * @{
  41. */
  42. /* Private define ------------------------------------------------------------*/
  43. /** @addtogroup COMP_Private_Constants
  44. * @{
  45. */
  46. /* Delay for COMP voltage scaler stabilization time (voltage from VrefInt, */
  47. /* delay based on VrefInt startup time). */
  48. /* Literal set to maximum value (refer to device datasheet, */
  49. /* parameter "TVREFINT"). */
  50. /* Unit: us */
  51. #define COMP_DELAY_VOLTAGE_SCALER_STAB_US ((uint32_t)3000U) /*!< Delay for COMP voltage scaler stabilization time */
  52. /**
  53. * @}
  54. */
  55. /* Exported functions --------------------------------------------------------*/
  56. /** @addtogroup COMPEx_Exported_Functions
  57. * @{
  58. */
  59. /** @addtogroup COMPEx_Exported_Functions_Group1
  60. * @brief Extended functions to manage VREFINT for the comparator
  61. *
  62. * @{
  63. */
  64. /**
  65. * @brief Enable Vrefint and path to comparator, used by comparator
  66. * instance COMP2 input based on VrefInt or subdivision of VrefInt.
  67. * @note The equivalent of this function is managed automatically when
  68. * using function "HAL_COMP_Init()".
  69. * @note VrefInt requires a startup time
  70. * (refer to device datasheet, parameter "TVREFINT").
  71. * This function waits for the startup time
  72. * (alternative solution: poll for bit SYSCFG_CFGR3_VREFINT_RDYF set).
  73. * @note VrefInt must be disabled before entering in low-power mode.
  74. * Refer to description of bit EN_VREFINT in reference manual.
  75. * @retval None
  76. */
  77. void HAL_COMPEx_EnableVREFINT(void)
  78. {
  79. __IO uint32_t wait_loop_index = 0U;
  80. /* Enable VrefInt voltage reference and buffer */
  81. SYSCFG->CFGR3 |= (SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP | SYSCFG_CFGR3_EN_VREFINT);
  82. /* Wait loop initialization and execution */
  83. /* Note: Variable divided by 2 to compensate partially */
  84. /* CPU processing cycles. */
  85. wait_loop_index = (COMP_DELAY_VOLTAGE_SCALER_STAB_US * (SystemCoreClock / (1000000U * 2U)));
  86. while(wait_loop_index != 0U)
  87. {
  88. wait_loop_index--;
  89. }
  90. }
  91. /**
  92. * @brief Disable Vrefint and path to comparator, used by comparator
  93. * instance COMP2 input based on VrefInt or subdivision of VrefInt.
  94. * @note VrefInt must be disabled before entering in low-power mode.
  95. * Refer to description of bit EN_VREFINT in reference manual.
  96. * @retval None
  97. */
  98. void HAL_COMPEx_DisableVREFINT(void)
  99. {
  100. /* Disable VrefInt voltage reference and buffer */
  101. SYSCFG->CFGR3 &= (uint32_t)~((uint32_t)(SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP | SYSCFG_CFGR3_EN_VREFINT));
  102. }
  103. /**
  104. * @}
  105. */
  106. /**
  107. * @}
  108. */
  109. /**
  110. * @}
  111. */
  112. #endif /* HAL_COMP_MODULE_ENABLED */
  113. /**
  114. * @}
  115. */
  116. #endif /* #if !defined (STM32L010xB) && !defined (STM32L010x8) && !defined (STM32L010x6) && !defined (STM32L010x4) */
  117. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/