mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
186:707f6e361f3e
mbed library release version 165

Who changed what in which revision?

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