Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
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.
 
 
 
 
 
 

150 lines
5.5 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</center></h2>
  22. *
  23. * Redistribution and use in source and binary forms, with or without modification,
  24. * are permitted provided that the following conditions are met:
  25. * 1. Redistributions of source code must retain the above copyright notice,
  26. * this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright notice,
  28. * this list of conditions and the following disclaimer in the documentation
  29. * and/or other materials provided with the distribution.
  30. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  31. * may be used to endorse or promote products derived from this software
  32. * without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  35. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  36. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  37. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  38. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  39. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  40. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  41. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  42. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  43. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. *
  45. ******************************************************************************
  46. */
  47. /* Includes ------------------------------------------------------------------*/
  48. #include "stm32l0xx_hal.h"
  49. /** @addtogroup STM32L0xx_HAL_Driver
  50. * @{
  51. */
  52. #ifdef HAL_COMP_MODULE_ENABLED
  53. /** @addtogroup COMPEx
  54. * @brief Extended COMP HAL module driver
  55. * @{
  56. */
  57. /* Private define ------------------------------------------------------------*/
  58. /** @addtogroup COMP_Private_Constants
  59. * @{
  60. */
  61. /* Delay for COMP voltage scaler stabilization time (voltage from VrefInt, */
  62. /* delay based on VrefInt startup time). */
  63. /* Literal set to maximum value (refer to device datasheet, */
  64. /* parameter "TVREFINT"). */
  65. /* Unit: us */
  66. #define COMP_DELAY_VOLTAGE_SCALER_STAB_US ((uint32_t)3000U) /*!< Delay for COMP voltage scaler stabilization time */
  67. /**
  68. * @}
  69. */
  70. /* Exported functions --------------------------------------------------------*/
  71. /** @addtogroup COMPEx_Exported_Functions
  72. * @{
  73. */
  74. /** @addtogroup COMPEx_Exported_Functions_Group1
  75. * @brief Extended functions to manage VREFINT for the comparator
  76. *
  77. * @{
  78. */
  79. /**
  80. * @brief Enable Vrefint and path to comparator, used by comparator
  81. * instance COMP2 input based on VrefInt or subdivision of VrefInt.
  82. * @note The equivalent of this function is managed automatically when
  83. * using function "HAL_COMP_Init()".
  84. * @note VrefInt requires a startup time
  85. * (refer to device datasheet, parameter "TVREFINT").
  86. * This function waits for the startup time
  87. * (alternative solution: poll for bit SYSCFG_CFGR3_VREFINT_RDYF set).
  88. * @retval None
  89. */
  90. void HAL_COMPEx_EnableVREFINT(void)
  91. {
  92. __IO uint32_t wait_loop_index = 0U;
  93. /* Enable the Buffer for the COMP by setting ENBUFLP_VREFINT_COMP bit in the CFGR3 register */
  94. SYSCFG->CFGR3 |= (SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP);
  95. /* Wait loop initialization and execution */
  96. /* Note: Variable divided by 2 to compensate partially */
  97. /* CPU processing cycles. */
  98. wait_loop_index = (COMP_DELAY_VOLTAGE_SCALER_STAB_US * (SystemCoreClock / (1000000U * 2U)));
  99. while(wait_loop_index != 0U)
  100. {
  101. wait_loop_index--;
  102. }
  103. }
  104. /**
  105. * @brief Disable Vrefint and path to comparator, used by comparator
  106. * instance COMP2 input based on VrefInt or subdivision of VrefInt.
  107. * @retval None
  108. */
  109. void HAL_COMPEx_DisableVREFINT(void)
  110. {
  111. /* Disable the Vrefint by resetting ENBUFLP_VREFINT_COMP bit in the CFGR3 register */
  112. SYSCFG->CFGR3 &= (uint32_t)~((uint32_t)(SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP));
  113. }
  114. /**
  115. * @}
  116. */
  117. /**
  118. * @}
  119. */
  120. /**
  121. * @}
  122. */
  123. #endif /* HAL_COMP_MODULE_ENABLED */
  124. /**
  125. * @}
  126. */
  127. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/