mbed library sources
Fork of mbed-src by
targets/cmsis/TARGET_STM/TARGET_DISCO_L053C8/stm32l0xx_hal.c@376:cb4d9db17537, 2014-10-31 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Oct 31 11:00:10 2014 +0000
- Revision:
- 376:cb4d9db17537
Synchronized with git revision 07b49da75eac883fc8916d3d6b6962664b8db29e
Full URL: https://github.com/mbedmicro/mbed/commit/07b49da75eac883fc8916d3d6b6962664b8db29e/
Targets: DISCO_L053C8 - new platform - STM32L0 Discovery board
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 376:cb4d9db17537 | 1 | /** |
mbed_official | 376:cb4d9db17537 | 2 | ****************************************************************************** |
mbed_official | 376:cb4d9db17537 | 3 | * @file stm32l0xx_hal.c |
mbed_official | 376:cb4d9db17537 | 4 | * @author MCD Application Team |
mbed_official | 376:cb4d9db17537 | 5 | * @version V1.1.0 |
mbed_official | 376:cb4d9db17537 | 6 | * @date 18-June-2014 |
mbed_official | 376:cb4d9db17537 | 7 | * @brief HAL module driver. |
mbed_official | 376:cb4d9db17537 | 8 | * This is the common part of the HAL initialization |
mbed_official | 376:cb4d9db17537 | 9 | * |
mbed_official | 376:cb4d9db17537 | 10 | @verbatim |
mbed_official | 376:cb4d9db17537 | 11 | ============================================================================== |
mbed_official | 376:cb4d9db17537 | 12 | ##### How to use this driver ##### |
mbed_official | 376:cb4d9db17537 | 13 | ============================================================================== |
mbed_official | 376:cb4d9db17537 | 14 | [..] |
mbed_official | 376:cb4d9db17537 | 15 | The common HAL driver contains a set of generic and common APIs that can be |
mbed_official | 376:cb4d9db17537 | 16 | used by the PPP peripheral drivers and the user to start using the HAL. |
mbed_official | 376:cb4d9db17537 | 17 | [..] |
mbed_official | 376:cb4d9db17537 | 18 | The HAL contains two APIs' categories: |
mbed_official | 376:cb4d9db17537 | 19 | (+) Common HAL APIs |
mbed_official | 376:cb4d9db17537 | 20 | (+) Services HAL APIs |
mbed_official | 376:cb4d9db17537 | 21 | |
mbed_official | 376:cb4d9db17537 | 22 | @endverbatim |
mbed_official | 376:cb4d9db17537 | 23 | ****************************************************************************** |
mbed_official | 376:cb4d9db17537 | 24 | * @attention |
mbed_official | 376:cb4d9db17537 | 25 | * |
mbed_official | 376:cb4d9db17537 | 26 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
mbed_official | 376:cb4d9db17537 | 27 | * |
mbed_official | 376:cb4d9db17537 | 28 | * Redistribution and use in source and binary forms, with or without modification, |
mbed_official | 376:cb4d9db17537 | 29 | * are permitted provided that the following conditions are met: |
mbed_official | 376:cb4d9db17537 | 30 | * 1. Redistributions of source code must retain the above copyright notice, |
mbed_official | 376:cb4d9db17537 | 31 | * this list of conditions and the following disclaimer. |
mbed_official | 376:cb4d9db17537 | 32 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
mbed_official | 376:cb4d9db17537 | 33 | * this list of conditions and the following disclaimer in the documentation |
mbed_official | 376:cb4d9db17537 | 34 | * and/or other materials provided with the distribution. |
mbed_official | 376:cb4d9db17537 | 35 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
mbed_official | 376:cb4d9db17537 | 36 | * may be used to endorse or promote products derived from this software |
mbed_official | 376:cb4d9db17537 | 37 | * without specific prior written permission. |
mbed_official | 376:cb4d9db17537 | 38 | * |
mbed_official | 376:cb4d9db17537 | 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
mbed_official | 376:cb4d9db17537 | 40 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
mbed_official | 376:cb4d9db17537 | 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
mbed_official | 376:cb4d9db17537 | 42 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
mbed_official | 376:cb4d9db17537 | 43 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
mbed_official | 376:cb4d9db17537 | 44 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
mbed_official | 376:cb4d9db17537 | 45 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
mbed_official | 376:cb4d9db17537 | 46 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
mbed_official | 376:cb4d9db17537 | 47 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
mbed_official | 376:cb4d9db17537 | 48 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mbed_official | 376:cb4d9db17537 | 49 | * |
mbed_official | 376:cb4d9db17537 | 50 | ****************************************************************************** |
mbed_official | 376:cb4d9db17537 | 51 | */ |
mbed_official | 376:cb4d9db17537 | 52 | |
mbed_official | 376:cb4d9db17537 | 53 | /* Includes ------------------------------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 54 | #include "stm32l0xx_hal.h" |
mbed_official | 376:cb4d9db17537 | 55 | |
mbed_official | 376:cb4d9db17537 | 56 | /** @addtogroup STM32L0xx_HAL_Driver |
mbed_official | 376:cb4d9db17537 | 57 | * @{ |
mbed_official | 376:cb4d9db17537 | 58 | */ |
mbed_official | 376:cb4d9db17537 | 59 | |
mbed_official | 376:cb4d9db17537 | 60 | /** @defgroup HAL |
mbed_official | 376:cb4d9db17537 | 61 | * @brief HAL module driver. |
mbed_official | 376:cb4d9db17537 | 62 | * @{ |
mbed_official | 376:cb4d9db17537 | 63 | */ |
mbed_official | 376:cb4d9db17537 | 64 | |
mbed_official | 376:cb4d9db17537 | 65 | #ifdef HAL_MODULE_ENABLED |
mbed_official | 376:cb4d9db17537 | 66 | |
mbed_official | 376:cb4d9db17537 | 67 | /* Private typedef -----------------------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 68 | /* Private define ------------------------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 69 | /** |
mbed_official | 376:cb4d9db17537 | 70 | * @brief STM32L0xx HAL Driver version number V1.1.0 |
mbed_official | 376:cb4d9db17537 | 71 | */ |
mbed_official | 376:cb4d9db17537 | 72 | #define __STM32L0xx_HAL_VERSION_MAIN (0x01) /*!< [31:24] main version */ |
mbed_official | 376:cb4d9db17537 | 73 | #define __STM32L0xx_HAL_VERSION_SUB1 (0x01) /*!< [23:16] sub1 version */ |
mbed_official | 376:cb4d9db17537 | 74 | #define __STM32L0xx_HAL_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */ |
mbed_official | 376:cb4d9db17537 | 75 | #define __STM32L0xx_HAL_VERSION_RC (0x00) /*!< [7:0] release candidate */ |
mbed_official | 376:cb4d9db17537 | 76 | #define __STM32L0xx_HAL_VERSION ((__STM32L0xx_HAL_VERSION_MAIN << 24)\ |
mbed_official | 376:cb4d9db17537 | 77 | |(__STM32L0xx_HAL_VERSION_SUB1 << 16)\ |
mbed_official | 376:cb4d9db17537 | 78 | |(__STM32L0xx_HAL_VERSION_SUB2 << 8 )\ |
mbed_official | 376:cb4d9db17537 | 79 | |(__STM32L0xx_HAL_VERSION_RC)) |
mbed_official | 376:cb4d9db17537 | 80 | |
mbed_official | 376:cb4d9db17537 | 81 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF) |
mbed_official | 376:cb4d9db17537 | 82 | /* Private macro -------------------------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 83 | /* Private variables ---------------------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 84 | static __IO uint32_t uwTick; |
mbed_official | 376:cb4d9db17537 | 85 | /* Private function prototypes -----------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 86 | /* Private functions ---------------------------------------------------------*/ |
mbed_official | 376:cb4d9db17537 | 87 | |
mbed_official | 376:cb4d9db17537 | 88 | /** @defgroup HAL_Private_Functions |
mbed_official | 376:cb4d9db17537 | 89 | * @{ |
mbed_official | 376:cb4d9db17537 | 90 | */ |
mbed_official | 376:cb4d9db17537 | 91 | |
mbed_official | 376:cb4d9db17537 | 92 | /** @defgroup HAL_Group1 Initialization and de-initialization Functions |
mbed_official | 376:cb4d9db17537 | 93 | * @brief Initialization and de-initialization functions |
mbed_official | 376:cb4d9db17537 | 94 | * |
mbed_official | 376:cb4d9db17537 | 95 | @verbatim |
mbed_official | 376:cb4d9db17537 | 96 | =============================================================================== |
mbed_official | 376:cb4d9db17537 | 97 | ##### Initialization and de-initialization functions ##### |
mbed_official | 376:cb4d9db17537 | 98 | =============================================================================== |
mbed_official | 376:cb4d9db17537 | 99 | [..] This section provides functions allowing to: |
mbed_official | 376:cb4d9db17537 | 100 | (+) Initializes the Flash interface, the NVIC allocation and initial clock |
mbed_official | 376:cb4d9db17537 | 101 | configuration. It initializes the source of time base also when timeout |
mbed_official | 376:cb4d9db17537 | 102 | is needed and the backup domain when enabled. |
mbed_official | 376:cb4d9db17537 | 103 | (+) de-Initializes common part of the HAL. |
mbed_official | 376:cb4d9db17537 | 104 | (+) Configure The time base source to have 1ms time base with a dedicated |
mbed_official | 376:cb4d9db17537 | 105 | Tick interrupt priority. |
mbed_official | 376:cb4d9db17537 | 106 | (++) Systick timer is used by default as source of time base, but user |
mbed_official | 376:cb4d9db17537 | 107 | can eventually implement his proper time base source (a general purpose |
mbed_official | 376:cb4d9db17537 | 108 | timer for example or other time source), keeping in mind that Time base |
mbed_official | 376:cb4d9db17537 | 109 | duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and |
mbed_official | 376:cb4d9db17537 | 110 | handled in milliseconds basis. |
mbed_official | 376:cb4d9db17537 | 111 | (++) Time base configuration function (HAL_InitTick ()) is called automatically |
mbed_official | 376:cb4d9db17537 | 112 | at the beginning of the program after reset by HAL_Init() or at any time |
mbed_official | 376:cb4d9db17537 | 113 | when clock is configured, by HAL_RCC_ClockConfig(). |
mbed_official | 376:cb4d9db17537 | 114 | (++) Source of time base is configured to generate interrupts at regular |
mbed_official | 376:cb4d9db17537 | 115 | time intervals. Care must be taken if HAL_Delay() is called from a |
mbed_official | 376:cb4d9db17537 | 116 | peripheral ISR process, the Tick interrupt line must have higher priority |
mbed_official | 376:cb4d9db17537 | 117 | (numerically lower) than the peripheral interrupt. Otherwise the caller |
mbed_official | 376:cb4d9db17537 | 118 | ISR process will be blocked. |
mbed_official | 376:cb4d9db17537 | 119 | (++) functions affecting time base configurations are declared as __Weak |
mbed_official | 376:cb4d9db17537 | 120 | to make override possible in case of other implementations in user file. |
mbed_official | 376:cb4d9db17537 | 121 | |
mbed_official | 376:cb4d9db17537 | 122 | @endverbatim |
mbed_official | 376:cb4d9db17537 | 123 | * @{ |
mbed_official | 376:cb4d9db17537 | 124 | */ |
mbed_official | 376:cb4d9db17537 | 125 | |
mbed_official | 376:cb4d9db17537 | 126 | /** |
mbed_official | 376:cb4d9db17537 | 127 | * @brief This function configures the Flash prefetch, Flash preread and Buffer cache, |
mbed_official | 376:cb4d9db17537 | 128 | * Configures time base source, NVIC and Low level hardware |
mbed_official | 376:cb4d9db17537 | 129 | * @note This function is called at the beginning of program after reset and before |
mbed_official | 376:cb4d9db17537 | 130 | * the clock configuration |
mbed_official | 376:cb4d9db17537 | 131 | * @note The time base configuration is based on MSI clock when exiting from Reset. |
mbed_official | 376:cb4d9db17537 | 132 | * Once done, time base tick start incrementing. |
mbed_official | 376:cb4d9db17537 | 133 | * In the default implementation,Systick is used as source of time base. |
mbed_official | 376:cb4d9db17537 | 134 | * the tick variable is incremented each 1ms in its ISR. |
mbed_official | 376:cb4d9db17537 | 135 | * @param None |
mbed_official | 376:cb4d9db17537 | 136 | * @retval HAL status |
mbed_official | 376:cb4d9db17537 | 137 | */ |
mbed_official | 376:cb4d9db17537 | 138 | HAL_StatusTypeDef HAL_Init(void) |
mbed_official | 376:cb4d9db17537 | 139 | { |
mbed_official | 376:cb4d9db17537 | 140 | /* Configure Buffer cache, Flash prefetch, Flash preread */ |
mbed_official | 376:cb4d9db17537 | 141 | #if (BUFFER_CACHE_DISABLE != 0) |
mbed_official | 376:cb4d9db17537 | 142 | __HAL_FLASH_BUFFER_CACHE_DISABLE(); |
mbed_official | 376:cb4d9db17537 | 143 | #endif /* BUFFER_CACHE_DISABLE */ |
mbed_official | 376:cb4d9db17537 | 144 | |
mbed_official | 376:cb4d9db17537 | 145 | #if (PREREAD_ENABLE != 0) |
mbed_official | 376:cb4d9db17537 | 146 | __HAL_FLASH_PREREAD_BUFFER_ENABLE(); |
mbed_official | 376:cb4d9db17537 | 147 | #endif /* PREREAD_ENABLE */ |
mbed_official | 376:cb4d9db17537 | 148 | |
mbed_official | 376:cb4d9db17537 | 149 | #if (PREFETCH_ENABLE != 0) |
mbed_official | 376:cb4d9db17537 | 150 | __HAL_FLASH_PREFETCH_BUFFER_ENABLE(); |
mbed_official | 376:cb4d9db17537 | 151 | #endif /* PREFETCH_ENABLE */ |
mbed_official | 376:cb4d9db17537 | 152 | |
mbed_official | 376:cb4d9db17537 | 153 | /* Use systick as time base source and configure 1ms tick (default clock after Reset is MSI) */ |
mbed_official | 376:cb4d9db17537 | 154 | |
mbed_official | 376:cb4d9db17537 | 155 | HAL_InitTick(TICK_INT_PRIORITY); |
mbed_official | 376:cb4d9db17537 | 156 | |
mbed_official | 376:cb4d9db17537 | 157 | /* Init the low level hardware */ |
mbed_official | 376:cb4d9db17537 | 158 | HAL_MspInit(); |
mbed_official | 376:cb4d9db17537 | 159 | |
mbed_official | 376:cb4d9db17537 | 160 | /* Return function status */ |
mbed_official | 376:cb4d9db17537 | 161 | return HAL_OK; |
mbed_official | 376:cb4d9db17537 | 162 | } |
mbed_official | 376:cb4d9db17537 | 163 | |
mbed_official | 376:cb4d9db17537 | 164 | /** |
mbed_official | 376:cb4d9db17537 | 165 | * @brief This function de-Initializes common part of the HAL and stops the source |
mbed_official | 376:cb4d9db17537 | 166 | * of time base. |
mbed_official | 376:cb4d9db17537 | 167 | * @note This function is optional. |
mbed_official | 376:cb4d9db17537 | 168 | * @param None |
mbed_official | 376:cb4d9db17537 | 169 | * @retval HAL status |
mbed_official | 376:cb4d9db17537 | 170 | */ |
mbed_official | 376:cb4d9db17537 | 171 | HAL_StatusTypeDef HAL_DeInit(void) |
mbed_official | 376:cb4d9db17537 | 172 | { |
mbed_official | 376:cb4d9db17537 | 173 | /* Reset of all peripherals */ |
mbed_official | 376:cb4d9db17537 | 174 | __APB1_FORCE_RESET(); |
mbed_official | 376:cb4d9db17537 | 175 | __APB1_RELEASE_RESET(); |
mbed_official | 376:cb4d9db17537 | 176 | |
mbed_official | 376:cb4d9db17537 | 177 | __APB2_FORCE_RESET(); |
mbed_official | 376:cb4d9db17537 | 178 | __APB2_RELEASE_RESET(); |
mbed_official | 376:cb4d9db17537 | 179 | |
mbed_official | 376:cb4d9db17537 | 180 | __AHB_FORCE_RESET(); |
mbed_official | 376:cb4d9db17537 | 181 | __AHB_RELEASE_RESET(); |
mbed_official | 376:cb4d9db17537 | 182 | |
mbed_official | 376:cb4d9db17537 | 183 | __IOP_FORCE_RESET(); |
mbed_official | 376:cb4d9db17537 | 184 | __IOP_RELEASE_RESET(); |
mbed_official | 376:cb4d9db17537 | 185 | |
mbed_official | 376:cb4d9db17537 | 186 | /* De-Init the low level hardware */ |
mbed_official | 376:cb4d9db17537 | 187 | HAL_MspDeInit(); |
mbed_official | 376:cb4d9db17537 | 188 | |
mbed_official | 376:cb4d9db17537 | 189 | /* Return function status */ |
mbed_official | 376:cb4d9db17537 | 190 | return HAL_OK; |
mbed_official | 376:cb4d9db17537 | 191 | } |
mbed_official | 376:cb4d9db17537 | 192 | |
mbed_official | 376:cb4d9db17537 | 193 | /** |
mbed_official | 376:cb4d9db17537 | 194 | * @brief Initializes the MSP. |
mbed_official | 376:cb4d9db17537 | 195 | * @param None |
mbed_official | 376:cb4d9db17537 | 196 | * @retval None |
mbed_official | 376:cb4d9db17537 | 197 | */ |
mbed_official | 376:cb4d9db17537 | 198 | __weak void HAL_MspInit(void) |
mbed_official | 376:cb4d9db17537 | 199 | { |
mbed_official | 376:cb4d9db17537 | 200 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 376:cb4d9db17537 | 201 | the HAL_MspInit could be implemented in the user file |
mbed_official | 376:cb4d9db17537 | 202 | */ |
mbed_official | 376:cb4d9db17537 | 203 | } |
mbed_official | 376:cb4d9db17537 | 204 | |
mbed_official | 376:cb4d9db17537 | 205 | /** |
mbed_official | 376:cb4d9db17537 | 206 | * @brief DeInitializes the MSP. |
mbed_official | 376:cb4d9db17537 | 207 | * @param None |
mbed_official | 376:cb4d9db17537 | 208 | * @retval None |
mbed_official | 376:cb4d9db17537 | 209 | */ |
mbed_official | 376:cb4d9db17537 | 210 | __weak void HAL_MspDeInit(void) |
mbed_official | 376:cb4d9db17537 | 211 | { |
mbed_official | 376:cb4d9db17537 | 212 | /* NOTE : This function Should not be modified, when the callback is needed, |
mbed_official | 376:cb4d9db17537 | 213 | the HAL_MspDeInit could be implemented in the user file |
mbed_official | 376:cb4d9db17537 | 214 | */ |
mbed_official | 376:cb4d9db17537 | 215 | } |
mbed_official | 376:cb4d9db17537 | 216 | |
mbed_official | 376:cb4d9db17537 | 217 | /** |
mbed_official | 376:cb4d9db17537 | 218 | * @} |
mbed_official | 376:cb4d9db17537 | 219 | */ |
mbed_official | 376:cb4d9db17537 | 220 | |
mbed_official | 376:cb4d9db17537 | 221 | /** |
mbed_official | 376:cb4d9db17537 | 222 | * @brief This function configures the source of the time base. |
mbed_official | 376:cb4d9db17537 | 223 | * The time source is configured to have 1ms time base with a dedicated |
mbed_official | 376:cb4d9db17537 | 224 | * Tick interrupt priority. |
mbed_official | 376:cb4d9db17537 | 225 | * @note This function is called automatically at the beginning of program after |
mbed_official | 376:cb4d9db17537 | 226 | * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig(). |
mbed_official | 376:cb4d9db17537 | 227 | * @note In the default implementation, SysTick timer is the source of time base. |
mbed_official | 376:cb4d9db17537 | 228 | * It is used to generate interrupts at regular time intervals. |
mbed_official | 376:cb4d9db17537 | 229 | * Care must be taken if HAL_Delay() is called from a peripheral ISR process, |
mbed_official | 376:cb4d9db17537 | 230 | * The the SysTick interrupt must have higher priority (numerically lower) |
mbed_official | 376:cb4d9db17537 | 231 | * than the peripheral interrupt. Otherwise the caller ISR process will be blocked. |
mbed_official | 376:cb4d9db17537 | 232 | * The function is declared as __Weak to be overwritten in case of other |
mbed_official | 376:cb4d9db17537 | 233 | * implementation in user file. |
mbed_official | 376:cb4d9db17537 | 234 | * @param TickPriority: Tick interrupt priority. |
mbed_official | 376:cb4d9db17537 | 235 | * @retval HAL status |
mbed_official | 376:cb4d9db17537 | 236 | */ |
mbed_official | 376:cb4d9db17537 | 237 | __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) |
mbed_official | 376:cb4d9db17537 | 238 | { |
mbed_official | 376:cb4d9db17537 | 239 | /*Configure the SysTick to have interrupt in 1ms time basis*/ |
mbed_official | 376:cb4d9db17537 | 240 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
mbed_official | 376:cb4d9db17537 | 241 | |
mbed_official | 376:cb4d9db17537 | 242 | /*Configure the SysTick IRQ priority */ |
mbed_official | 376:cb4d9db17537 | 243 | HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0); |
mbed_official | 376:cb4d9db17537 | 244 | |
mbed_official | 376:cb4d9db17537 | 245 | /* Return function status */ |
mbed_official | 376:cb4d9db17537 | 246 | return HAL_OK; |
mbed_official | 376:cb4d9db17537 | 247 | } |
mbed_official | 376:cb4d9db17537 | 248 | |
mbed_official | 376:cb4d9db17537 | 249 | /** @defgroup HAL_Group2 HAL Control functions |
mbed_official | 376:cb4d9db17537 | 250 | * @brief HAL Control functions |
mbed_official | 376:cb4d9db17537 | 251 | * |
mbed_official | 376:cb4d9db17537 | 252 | @verbatim |
mbed_official | 376:cb4d9db17537 | 253 | =============================================================================== |
mbed_official | 376:cb4d9db17537 | 254 | ##### HAL Control functions ##### |
mbed_official | 376:cb4d9db17537 | 255 | =============================================================================== |
mbed_official | 376:cb4d9db17537 | 256 | [..] This section provides functions allowing to: |
mbed_official | 376:cb4d9db17537 | 257 | (+) Provide a tick value in millisecond |
mbed_official | 376:cb4d9db17537 | 258 | (+) Provide a blocking delay in millisecond |
mbed_official | 376:cb4d9db17537 | 259 | (+) Suspend the time base source interrupt |
mbed_official | 376:cb4d9db17537 | 260 | (+) Resume the time base source interrupt |
mbed_official | 376:cb4d9db17537 | 261 | (+) Get the HAL API driver version |
mbed_official | 376:cb4d9db17537 | 262 | (+) Get the device identifier |
mbed_official | 376:cb4d9db17537 | 263 | (+) Get the device revision identifier |
mbed_official | 376:cb4d9db17537 | 264 | (+) Configures low power mode behavior when the MCU is in Debug mode |
mbed_official | 376:cb4d9db17537 | 265 | |
mbed_official | 376:cb4d9db17537 | 266 | @endverbatim |
mbed_official | 376:cb4d9db17537 | 267 | * @{ |
mbed_official | 376:cb4d9db17537 | 268 | */ |
mbed_official | 376:cb4d9db17537 | 269 | |
mbed_official | 376:cb4d9db17537 | 270 | /** |
mbed_official | 376:cb4d9db17537 | 271 | * @brief This function is called to increment a global variable "uwTick" |
mbed_official | 376:cb4d9db17537 | 272 | * used as application time base. |
mbed_official | 376:cb4d9db17537 | 273 | * @note In the default implementation, this variable is incremented each 1ms |
mbed_official | 376:cb4d9db17537 | 274 | * in Systick ISR. |
mbed_official | 376:cb4d9db17537 | 275 | * @note This function is declared as __weak to be overwritten in case of other |
mbed_official | 376:cb4d9db17537 | 276 | * implementations in user file. |
mbed_official | 376:cb4d9db17537 | 277 | * @param None |
mbed_official | 376:cb4d9db17537 | 278 | * @retval None |
mbed_official | 376:cb4d9db17537 | 279 | */ |
mbed_official | 376:cb4d9db17537 | 280 | __weak void HAL_IncTick(void) |
mbed_official | 376:cb4d9db17537 | 281 | { |
mbed_official | 376:cb4d9db17537 | 282 | uwTick++; |
mbed_official | 376:cb4d9db17537 | 283 | } |
mbed_official | 376:cb4d9db17537 | 284 | |
mbed_official | 376:cb4d9db17537 | 285 | /** |
mbed_official | 376:cb4d9db17537 | 286 | * @brief Provides a tick value in millisecond. |
mbed_official | 376:cb4d9db17537 | 287 | * @note This function is declared as __weak to be overwritten in case of other |
mbed_official | 376:cb4d9db17537 | 288 | * implementations in user file. |
mbed_official | 376:cb4d9db17537 | 289 | * @param None |
mbed_official | 376:cb4d9db17537 | 290 | * @retval tick value |
mbed_official | 376:cb4d9db17537 | 291 | */ |
mbed_official | 376:cb4d9db17537 | 292 | __weak uint32_t HAL_GetTick(void) |
mbed_official | 376:cb4d9db17537 | 293 | { |
mbed_official | 376:cb4d9db17537 | 294 | return uwTick; |
mbed_official | 376:cb4d9db17537 | 295 | } |
mbed_official | 376:cb4d9db17537 | 296 | |
mbed_official | 376:cb4d9db17537 | 297 | /** |
mbed_official | 376:cb4d9db17537 | 298 | * @brief This function provides accurate delay (in milliseconds) based |
mbed_official | 376:cb4d9db17537 | 299 | * on variable incremented. |
mbed_official | 376:cb4d9db17537 | 300 | * @note In the default implementation , SysTick timer is the source of time base. |
mbed_official | 376:cb4d9db17537 | 301 | * It is used to generate interrupts at regular time intervals where uwTick |
mbed_official | 376:cb4d9db17537 | 302 | * is incremented. |
mbed_official | 376:cb4d9db17537 | 303 | * @note ThiS function is declared as __weak to be overwritten in case of other |
mbed_official | 376:cb4d9db17537 | 304 | * implementations in user file. |
mbed_official | 376:cb4d9db17537 | 305 | * @param Delay: specifies the delay time length, in milliseconds. |
mbed_official | 376:cb4d9db17537 | 306 | * @retval None |
mbed_official | 376:cb4d9db17537 | 307 | */ |
mbed_official | 376:cb4d9db17537 | 308 | __weak void HAL_Delay(__IO uint32_t Delay) |
mbed_official | 376:cb4d9db17537 | 309 | { |
mbed_official | 376:cb4d9db17537 | 310 | uint32_t tickstart = 0; |
mbed_official | 376:cb4d9db17537 | 311 | tickstart = HAL_GetTick(); |
mbed_official | 376:cb4d9db17537 | 312 | while((HAL_GetTick() - tickstart) < Delay) |
mbed_official | 376:cb4d9db17537 | 313 | { |
mbed_official | 376:cb4d9db17537 | 314 | } |
mbed_official | 376:cb4d9db17537 | 315 | } |
mbed_official | 376:cb4d9db17537 | 316 | |
mbed_official | 376:cb4d9db17537 | 317 | /** |
mbed_official | 376:cb4d9db17537 | 318 | * @brief Suspend Tick increment. |
mbed_official | 376:cb4d9db17537 | 319 | * @note In the default implementation , SysTick timer is the source of time base. It is |
mbed_official | 376:cb4d9db17537 | 320 | * used to generate interrupts at regular time intervals. Once HAL_SuspendTick() |
mbed_official | 376:cb4d9db17537 | 321 | * is called, the the SysTick interrupt will be disabled and so Tick increment |
mbed_official | 376:cb4d9db17537 | 322 | * is suspended. |
mbed_official | 376:cb4d9db17537 | 323 | * @note This function is declared as __weak to be overwritten in case of other |
mbed_official | 376:cb4d9db17537 | 324 | * implementations in user file. |
mbed_official | 376:cb4d9db17537 | 325 | * @param None |
mbed_official | 376:cb4d9db17537 | 326 | * @retval None |
mbed_official | 376:cb4d9db17537 | 327 | */ |
mbed_official | 376:cb4d9db17537 | 328 | __weak void HAL_SuspendTick(void) |
mbed_official | 376:cb4d9db17537 | 329 | { |
mbed_official | 376:cb4d9db17537 | 330 | /* Disable SysTick Interrupt */ |
mbed_official | 376:cb4d9db17537 | 331 | SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; |
mbed_official | 376:cb4d9db17537 | 332 | } |
mbed_official | 376:cb4d9db17537 | 333 | |
mbed_official | 376:cb4d9db17537 | 334 | /** |
mbed_official | 376:cb4d9db17537 | 335 | * @brief Resume Tick increment. |
mbed_official | 376:cb4d9db17537 | 336 | * @note In the default implementation , SysTick timer is the source of time base. It is |
mbed_official | 376:cb4d9db17537 | 337 | * used to generate interrupts at regular time intervals. Once HAL_ResumeTick() |
mbed_official | 376:cb4d9db17537 | 338 | * is called, the the SysTick interrupt will be enabled and so Tick increment |
mbed_official | 376:cb4d9db17537 | 339 | * is resumed. |
mbed_official | 376:cb4d9db17537 | 340 | * @note This function is declared as __weak to be overwritten in case of other |
mbed_official | 376:cb4d9db17537 | 341 | * implementations in user file. |
mbed_official | 376:cb4d9db17537 | 342 | * @param None |
mbed_official | 376:cb4d9db17537 | 343 | * @retval None |
mbed_official | 376:cb4d9db17537 | 344 | */ |
mbed_official | 376:cb4d9db17537 | 345 | __weak void HAL_ResumeTick(void) |
mbed_official | 376:cb4d9db17537 | 346 | { |
mbed_official | 376:cb4d9db17537 | 347 | /* Enable SysTick Interrupt */ |
mbed_official | 376:cb4d9db17537 | 348 | SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; |
mbed_official | 376:cb4d9db17537 | 349 | } |
mbed_official | 376:cb4d9db17537 | 350 | |
mbed_official | 376:cb4d9db17537 | 351 | /** |
mbed_official | 376:cb4d9db17537 | 352 | * @brief Returns the HAL revision |
mbed_official | 376:cb4d9db17537 | 353 | * @param None |
mbed_official | 376:cb4d9db17537 | 354 | * @retval version: 0xXYZR (8bits for each decimal, R for RC) |
mbed_official | 376:cb4d9db17537 | 355 | */ |
mbed_official | 376:cb4d9db17537 | 356 | uint32_t HAL_GetHalVersion(void) |
mbed_official | 376:cb4d9db17537 | 357 | { |
mbed_official | 376:cb4d9db17537 | 358 | return __STM32L0xx_HAL_VERSION; |
mbed_official | 376:cb4d9db17537 | 359 | } |
mbed_official | 376:cb4d9db17537 | 360 | |
mbed_official | 376:cb4d9db17537 | 361 | /** |
mbed_official | 376:cb4d9db17537 | 362 | * @brief Returns the device revision identifier. |
mbed_official | 376:cb4d9db17537 | 363 | * @param None |
mbed_official | 376:cb4d9db17537 | 364 | * @retval Device revision identifier |
mbed_official | 376:cb4d9db17537 | 365 | */ |
mbed_official | 376:cb4d9db17537 | 366 | uint32_t HAL_GetREVID(void) |
mbed_official | 376:cb4d9db17537 | 367 | { |
mbed_official | 376:cb4d9db17537 | 368 | return((DBGMCU->IDCODE) >> 16); |
mbed_official | 376:cb4d9db17537 | 369 | } |
mbed_official | 376:cb4d9db17537 | 370 | |
mbed_official | 376:cb4d9db17537 | 371 | /** |
mbed_official | 376:cb4d9db17537 | 372 | * @brief Returns the device identifier. |
mbed_official | 376:cb4d9db17537 | 373 | * @param None |
mbed_official | 376:cb4d9db17537 | 374 | * @retval Device identifier |
mbed_official | 376:cb4d9db17537 | 375 | */ |
mbed_official | 376:cb4d9db17537 | 376 | uint32_t HAL_GetDEVID(void) |
mbed_official | 376:cb4d9db17537 | 377 | { |
mbed_official | 376:cb4d9db17537 | 378 | return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK); |
mbed_official | 376:cb4d9db17537 | 379 | } |
mbed_official | 376:cb4d9db17537 | 380 | |
mbed_official | 376:cb4d9db17537 | 381 | /** |
mbed_official | 376:cb4d9db17537 | 382 | * @brief Enable the Debug Module during SLEEP mode |
mbed_official | 376:cb4d9db17537 | 383 | * @param None |
mbed_official | 376:cb4d9db17537 | 384 | * @retval None |
mbed_official | 376:cb4d9db17537 | 385 | */ |
mbed_official | 376:cb4d9db17537 | 386 | void HAL_EnableDBGSleepMode(void) |
mbed_official | 376:cb4d9db17537 | 387 | { |
mbed_official | 376:cb4d9db17537 | 388 | SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); |
mbed_official | 376:cb4d9db17537 | 389 | } |
mbed_official | 376:cb4d9db17537 | 390 | |
mbed_official | 376:cb4d9db17537 | 391 | /** |
mbed_official | 376:cb4d9db17537 | 392 | * @brief Disable the Debug Module during SLEEP mode |
mbed_official | 376:cb4d9db17537 | 393 | * @param None |
mbed_official | 376:cb4d9db17537 | 394 | * @retval None |
mbed_official | 376:cb4d9db17537 | 395 | */ |
mbed_official | 376:cb4d9db17537 | 396 | void HAL_DisableDBGSleepMode(void) |
mbed_official | 376:cb4d9db17537 | 397 | { |
mbed_official | 376:cb4d9db17537 | 398 | CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); |
mbed_official | 376:cb4d9db17537 | 399 | } |
mbed_official | 376:cb4d9db17537 | 400 | |
mbed_official | 376:cb4d9db17537 | 401 | /** |
mbed_official | 376:cb4d9db17537 | 402 | * @brief Enable the Debug Module during STOP mode |
mbed_official | 376:cb4d9db17537 | 403 | * @param None |
mbed_official | 376:cb4d9db17537 | 404 | * @retval None |
mbed_official | 376:cb4d9db17537 | 405 | */ |
mbed_official | 376:cb4d9db17537 | 406 | void HAL_EnableDBGStopMode(void) |
mbed_official | 376:cb4d9db17537 | 407 | { |
mbed_official | 376:cb4d9db17537 | 408 | SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); |
mbed_official | 376:cb4d9db17537 | 409 | } |
mbed_official | 376:cb4d9db17537 | 410 | |
mbed_official | 376:cb4d9db17537 | 411 | /** |
mbed_official | 376:cb4d9db17537 | 412 | * @brief Disable the Debug Module during STOP mode |
mbed_official | 376:cb4d9db17537 | 413 | * @param None |
mbed_official | 376:cb4d9db17537 | 414 | * @retval None |
mbed_official | 376:cb4d9db17537 | 415 | */ |
mbed_official | 376:cb4d9db17537 | 416 | void HAL_DisableDBGStopMode(void) |
mbed_official | 376:cb4d9db17537 | 417 | { |
mbed_official | 376:cb4d9db17537 | 418 | CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); |
mbed_official | 376:cb4d9db17537 | 419 | } |
mbed_official | 376:cb4d9db17537 | 420 | |
mbed_official | 376:cb4d9db17537 | 421 | /** |
mbed_official | 376:cb4d9db17537 | 422 | * @brief Enable the Debug Module during STANDBY mode |
mbed_official | 376:cb4d9db17537 | 423 | * @param None |
mbed_official | 376:cb4d9db17537 | 424 | * @retval None |
mbed_official | 376:cb4d9db17537 | 425 | */ |
mbed_official | 376:cb4d9db17537 | 426 | void HAL_EnableDBGStandbyMode(void) |
mbed_official | 376:cb4d9db17537 | 427 | { |
mbed_official | 376:cb4d9db17537 | 428 | SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); |
mbed_official | 376:cb4d9db17537 | 429 | } |
mbed_official | 376:cb4d9db17537 | 430 | |
mbed_official | 376:cb4d9db17537 | 431 | /** |
mbed_official | 376:cb4d9db17537 | 432 | * @brief Disable the Debug Module during STANDBY mode |
mbed_official | 376:cb4d9db17537 | 433 | * @param None |
mbed_official | 376:cb4d9db17537 | 434 | * @retval None |
mbed_official | 376:cb4d9db17537 | 435 | */ |
mbed_official | 376:cb4d9db17537 | 436 | void HAL_DisableDBGStandbyMode(void) |
mbed_official | 376:cb4d9db17537 | 437 | { |
mbed_official | 376:cb4d9db17537 | 438 | CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); |
mbed_official | 376:cb4d9db17537 | 439 | } |
mbed_official | 376:cb4d9db17537 | 440 | |
mbed_official | 376:cb4d9db17537 | 441 | /** |
mbed_official | 376:cb4d9db17537 | 442 | * @brief Configures low power mode behavior when the MCU is in Debug mode. |
mbed_official | 376:cb4d9db17537 | 443 | * @param Periph: specifies the low power mode. |
mbed_official | 376:cb4d9db17537 | 444 | * This parameter can be any combination of the following values: |
mbed_official | 376:cb4d9db17537 | 445 | * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode |
mbed_official | 376:cb4d9db17537 | 446 | * @arg DBGMCU_STOP: Keep debugger connection during STOP mode |
mbed_official | 376:cb4d9db17537 | 447 | * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode |
mbed_official | 376:cb4d9db17537 | 448 | * @param NewState: new state of the specified low power mode in Debug mode. |
mbed_official | 376:cb4d9db17537 | 449 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 376:cb4d9db17537 | 450 | * @retval None |
mbed_official | 376:cb4d9db17537 | 451 | */ |
mbed_official | 376:cb4d9db17537 | 452 | void HAL_DBG_LowPowerConfig(uint32_t Periph, FunctionalState NewState) |
mbed_official | 376:cb4d9db17537 | 453 | { |
mbed_official | 376:cb4d9db17537 | 454 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 455 | assert_param(IS_DBGMCU_PERIPH(Periph)); |
mbed_official | 376:cb4d9db17537 | 456 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 376:cb4d9db17537 | 457 | if (NewState != DISABLE) |
mbed_official | 376:cb4d9db17537 | 458 | { |
mbed_official | 376:cb4d9db17537 | 459 | DBGMCU->CR |= Periph; |
mbed_official | 376:cb4d9db17537 | 460 | } |
mbed_official | 376:cb4d9db17537 | 461 | else |
mbed_official | 376:cb4d9db17537 | 462 | { |
mbed_official | 376:cb4d9db17537 | 463 | DBGMCU->CR &= ~Periph; |
mbed_official | 376:cb4d9db17537 | 464 | } |
mbed_official | 376:cb4d9db17537 | 465 | } |
mbed_official | 376:cb4d9db17537 | 466 | |
mbed_official | 376:cb4d9db17537 | 467 | /** |
mbed_official | 376:cb4d9db17537 | 468 | * @brief Returns the boot mode as configured by user. |
mbed_official | 376:cb4d9db17537 | 469 | * @param None. |
mbed_official | 376:cb4d9db17537 | 470 | * @retval The boot mode as configured by user. The returned value can be one |
mbed_official | 376:cb4d9db17537 | 471 | * of the following values: |
mbed_official | 376:cb4d9db17537 | 472 | * - 0x00000000: Boot is configured in Main Flash memory |
mbed_official | 376:cb4d9db17537 | 473 | * - 0x00000100: Boot is configured in System Flash memory |
mbed_official | 376:cb4d9db17537 | 474 | * - 0x00000300: Boot is configured in Embedded SRAM memory |
mbed_official | 376:cb4d9db17537 | 475 | */ |
mbed_official | 376:cb4d9db17537 | 476 | uint32_t HAL_GetBootMode(void) |
mbed_official | 376:cb4d9db17537 | 477 | { |
mbed_official | 376:cb4d9db17537 | 478 | return (SYSCFG->CFGR1 & SYSCFG_CFGR1_BOOT_MODE); |
mbed_official | 376:cb4d9db17537 | 479 | } |
mbed_official | 376:cb4d9db17537 | 480 | |
mbed_official | 376:cb4d9db17537 | 481 | /** |
mbed_official | 376:cb4d9db17537 | 482 | * @brief Configures the I2C fast mode plus driving capability. |
mbed_official | 376:cb4d9db17537 | 483 | * @param SYSCFG_I2CFastModePlus: selects the pin. |
mbed_official | 376:cb4d9db17537 | 484 | * This parameter can be one of the following values: |
mbed_official | 376:cb4d9db17537 | 485 | * @arg SYSCFG_I2CFastModePlus_PB6: Configure fast mode plus driving capability for PB6 |
mbed_official | 376:cb4d9db17537 | 486 | * @arg SYSCFG_I2CFastModePlus_PB7: Configure fast mode plus driving capability for PB7 |
mbed_official | 376:cb4d9db17537 | 487 | * @arg SYSCFG_I2CFastModePlus_PB8: Configure fast mode plus driving capability for PB8 |
mbed_official | 376:cb4d9db17537 | 488 | * @arg SYSCFG_I2CFastModePlus_PB9: Configure fast mode plus driving capability for PB9 |
mbed_official | 376:cb4d9db17537 | 489 | * @arg SYSCFG_I2CFastModePlus_I2C1: Configure fast mode plus driving capability for I2C1 pins |
mbed_official | 376:cb4d9db17537 | 490 | * @arg SYSCFG_I2CFastModePlus_I2C2: Configure fast mode plus driving capability for I2C2 pins |
mbed_official | 376:cb4d9db17537 | 491 | * @param NewState: This parameter can be: |
mbed_official | 376:cb4d9db17537 | 492 | * ENABLE: Enable fast mode plus driving capability for selected I2C pin |
mbed_official | 376:cb4d9db17537 | 493 | * DISABLE: Disable fast mode plus driving capability for selected I2C pin |
mbed_official | 376:cb4d9db17537 | 494 | * @note For I2C1, fast mode plus driving capability can be enabled on all selected |
mbed_official | 376:cb4d9db17537 | 495 | * I2C1 pins using SYSCFG_I2CFastModePlus_I2C1 parameter or independently |
mbed_official | 376:cb4d9db17537 | 496 | * on each one of the following pins PB6, PB7, PB8 and PB9. |
mbed_official | 376:cb4d9db17537 | 497 | * @note For remaining I2C1 pins (PA14, PA15...) fast mode plus driving capability |
mbed_official | 376:cb4d9db17537 | 498 | * can be enabled only by using SYSCFG_I2CFastModePlus_I2C1 parameter. |
mbed_official | 376:cb4d9db17537 | 499 | * @note For all I2C2 pins fast mode plus driving capability can be enabled |
mbed_official | 376:cb4d9db17537 | 500 | * only by using SYSCFG_I2CFastModePlus_I2C2 parameter. |
mbed_official | 376:cb4d9db17537 | 501 | * @retval None |
mbed_official | 376:cb4d9db17537 | 502 | */ |
mbed_official | 376:cb4d9db17537 | 503 | void HAL_I2CFastModePlusConfig(uint32_t SYSCFG_I2CFastModePlus, FunctionalState NewState) |
mbed_official | 376:cb4d9db17537 | 504 | { |
mbed_official | 376:cb4d9db17537 | 505 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 506 | assert_param(IS_SYSCFG_I2C_FMP(SYSCFG_I2CFastModePlus)); |
mbed_official | 376:cb4d9db17537 | 507 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 376:cb4d9db17537 | 508 | |
mbed_official | 376:cb4d9db17537 | 509 | if (NewState != DISABLE) |
mbed_official | 376:cb4d9db17537 | 510 | { |
mbed_official | 376:cb4d9db17537 | 511 | /* Enable fast mode plus driving capability for selected pin */ |
mbed_official | 376:cb4d9db17537 | 512 | SYSCFG->CFGR2 |= (uint32_t)SYSCFG_I2CFastModePlus; |
mbed_official | 376:cb4d9db17537 | 513 | } |
mbed_official | 376:cb4d9db17537 | 514 | else |
mbed_official | 376:cb4d9db17537 | 515 | { |
mbed_official | 376:cb4d9db17537 | 516 | /* Disable fast mode plus driving capability for selected pin */ |
mbed_official | 376:cb4d9db17537 | 517 | SYSCFG->CFGR2 &= (uint32_t)(~SYSCFG_I2CFastModePlus); |
mbed_official | 376:cb4d9db17537 | 518 | } |
mbed_official | 376:cb4d9db17537 | 519 | } |
mbed_official | 376:cb4d9db17537 | 520 | |
mbed_official | 376:cb4d9db17537 | 521 | /** |
mbed_official | 376:cb4d9db17537 | 522 | * @brief Enables or disables the VREFINT. |
mbed_official | 376:cb4d9db17537 | 523 | * @param NewState: new state of the Vrefint. |
mbed_official | 376:cb4d9db17537 | 524 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 376:cb4d9db17537 | 525 | * @retval None |
mbed_official | 376:cb4d9db17537 | 526 | */ |
mbed_official | 376:cb4d9db17537 | 527 | void HAL_VREFINT_Cmd(FunctionalState NewState) |
mbed_official | 376:cb4d9db17537 | 528 | { |
mbed_official | 376:cb4d9db17537 | 529 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 530 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 376:cb4d9db17537 | 531 | |
mbed_official | 376:cb4d9db17537 | 532 | if (NewState != DISABLE) |
mbed_official | 376:cb4d9db17537 | 533 | { |
mbed_official | 376:cb4d9db17537 | 534 | /* Enable the VREFINT by setting EN_VREFINT bit in the CFGR3 register */ |
mbed_official | 376:cb4d9db17537 | 535 | SYSCFG->CFGR3 |= SYSCFG_CFGR3_EN_VREFINT; |
mbed_official | 376:cb4d9db17537 | 536 | } |
mbed_official | 376:cb4d9db17537 | 537 | else |
mbed_official | 376:cb4d9db17537 | 538 | { |
mbed_official | 376:cb4d9db17537 | 539 | /* Disable the VREFINT by setting EN_VREFINT bit in the CFGR3 register */ |
mbed_official | 376:cb4d9db17537 | 540 | SYSCFG->CFGR3 &= (uint32_t)~((uint32_t)SYSCFG_CFGR3_EN_VREFINT); |
mbed_official | 376:cb4d9db17537 | 541 | } |
mbed_official | 376:cb4d9db17537 | 542 | } |
mbed_official | 376:cb4d9db17537 | 543 | |
mbed_official | 376:cb4d9db17537 | 544 | /** |
mbed_official | 376:cb4d9db17537 | 545 | * @brief Selects the output of internal reference voltage (VREFINT). |
mbed_official | 376:cb4d9db17537 | 546 | * The VREFINT output can be routed to(PB0) or |
mbed_official | 376:cb4d9db17537 | 547 | * (PB1) or both. |
mbed_official | 376:cb4d9db17537 | 548 | * @param SYSCFG_Vrefint_OUTPUT: new state of the Vrefint output. |
mbed_official | 376:cb4d9db17537 | 549 | * This parameter can be one of the following values: |
mbed_official | 376:cb4d9db17537 | 550 | * @arg SYSCFG_VREFINT_OUT_NONE |
mbed_official | 376:cb4d9db17537 | 551 | * @arg SYSCFG_VREFINT_OUT_PB0 |
mbed_official | 376:cb4d9db17537 | 552 | * @arg SYSCFG_VREFINT_OUT_PB1 |
mbed_official | 376:cb4d9db17537 | 553 | * @arg SYSCFG_VREFINT_OUT_PB0_PB1 |
mbed_official | 376:cb4d9db17537 | 554 | * @retval None |
mbed_official | 376:cb4d9db17537 | 555 | */ |
mbed_official | 376:cb4d9db17537 | 556 | void HAL_VREFINT_OutputSelect(uint32_t SYSCFG_Vrefint_OUTPUT) |
mbed_official | 376:cb4d9db17537 | 557 | { |
mbed_official | 376:cb4d9db17537 | 558 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 559 | assert_param(IS_SYSCFG_VREFINT_OUT_SELECT(SYSCFG_Vrefint_OUTPUT)); |
mbed_official | 376:cb4d9db17537 | 560 | |
mbed_official | 376:cb4d9db17537 | 561 | /* Set the output Vrefint pin */ |
mbed_official | 376:cb4d9db17537 | 562 | SYSCFG->CFGR3 &= ~(SYSCFG_CFGR3_VREF_OUT); |
mbed_official | 376:cb4d9db17537 | 563 | SYSCFG->CFGR3 |= (uint32_t)(SYSCFG_Vrefint_OUTPUT); |
mbed_official | 376:cb4d9db17537 | 564 | } |
mbed_official | 376:cb4d9db17537 | 565 | |
mbed_official | 376:cb4d9db17537 | 566 | /** |
mbed_official | 376:cb4d9db17537 | 567 | * @brief Enables or disables the Buffer Vrefint for the ADC. |
mbed_official | 376:cb4d9db17537 | 568 | * @param NewState: new state of the Vrefint. |
mbed_official | 376:cb4d9db17537 | 569 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 376:cb4d9db17537 | 570 | * @note This is functional only if the LOCK is not set |
mbed_official | 376:cb4d9db17537 | 571 | * @retval None |
mbed_official | 376:cb4d9db17537 | 572 | */ |
mbed_official | 376:cb4d9db17537 | 573 | void HAL_ADC_EnableBuffer_Cmd(FunctionalState NewState) |
mbed_official | 376:cb4d9db17537 | 574 | { |
mbed_official | 376:cb4d9db17537 | 575 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 576 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 376:cb4d9db17537 | 577 | |
mbed_official | 376:cb4d9db17537 | 578 | if (NewState != DISABLE) |
mbed_official | 376:cb4d9db17537 | 579 | { |
mbed_official | 376:cb4d9db17537 | 580 | /* Enable the Buffer for the ADC by setting EN_VREFINT bit and the ENBUF_VREFINT_ADC in the CFGR3 register */ |
mbed_official | 376:cb4d9db17537 | 581 | SYSCFG->CFGR3 |= (SYSCFG_CFGR3_ENBUF_VREFINT_ADC | SYSCFG_CFGR3_EN_VREFINT); |
mbed_official | 376:cb4d9db17537 | 582 | } |
mbed_official | 376:cb4d9db17537 | 583 | else |
mbed_official | 376:cb4d9db17537 | 584 | { |
mbed_official | 376:cb4d9db17537 | 585 | /* Disable the Vrefint by resetting ENBUF_BGAP_ADC bit and the EN_VREFINT bit in the CFGR3 register */ |
mbed_official | 376:cb4d9db17537 | 586 | SYSCFG->CFGR3 &= (uint32_t)~((uint32_t)(SYSCFG_CFGR3_ENBUF_VREFINT_ADC | SYSCFG_CFGR3_EN_VREFINT)); |
mbed_official | 376:cb4d9db17537 | 587 | } |
mbed_official | 376:cb4d9db17537 | 588 | } |
mbed_official | 376:cb4d9db17537 | 589 | |
mbed_official | 376:cb4d9db17537 | 590 | /** |
mbed_official | 376:cb4d9db17537 | 591 | * @brief Enables or disables the Buffer Sensor for the ADC. |
mbed_official | 376:cb4d9db17537 | 592 | * @param NewState: new state of the Vrefint. |
mbed_official | 376:cb4d9db17537 | 593 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 376:cb4d9db17537 | 594 | * @note This is functional only if the LOCK is not set. |
mbed_official | 376:cb4d9db17537 | 595 | * @retval None |
mbed_official | 376:cb4d9db17537 | 596 | */ |
mbed_official | 376:cb4d9db17537 | 597 | void HAL_ADC_EnableBufferSensor_Cmd(FunctionalState NewState) |
mbed_official | 376:cb4d9db17537 | 598 | { |
mbed_official | 376:cb4d9db17537 | 599 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 600 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 376:cb4d9db17537 | 601 | |
mbed_official | 376:cb4d9db17537 | 602 | if (NewState != DISABLE) |
mbed_official | 376:cb4d9db17537 | 603 | { |
mbed_official | 376:cb4d9db17537 | 604 | /* Enable the Buffer for the ADC by setting EN_VREFINT bit and the ENBUF_SENSOR_ADC in the CFGR3 register */ |
mbed_official | 376:cb4d9db17537 | 605 | SYSCFG->CFGR3 |= (SYSCFG_CFGR3_ENBUF_SENSOR_ADC | SYSCFG_CFGR3_EN_VREFINT); |
mbed_official | 376:cb4d9db17537 | 606 | } |
mbed_official | 376:cb4d9db17537 | 607 | else |
mbed_official | 376:cb4d9db17537 | 608 | { |
mbed_official | 376:cb4d9db17537 | 609 | /* Disable the Vrefint by resetting EN_VREFINT bit and the ENBUF_SENSOR_ADC in the CFGR3 register */ |
mbed_official | 376:cb4d9db17537 | 610 | SYSCFG->CFGR3 &= (uint32_t)~((uint32_t)(SYSCFG_CFGR3_ENBUF_SENSOR_ADC | SYSCFG_CFGR3_EN_VREFINT)); |
mbed_official | 376:cb4d9db17537 | 611 | } |
mbed_official | 376:cb4d9db17537 | 612 | } |
mbed_official | 376:cb4d9db17537 | 613 | |
mbed_official | 376:cb4d9db17537 | 614 | /** |
mbed_official | 376:cb4d9db17537 | 615 | * @brief Enables or disables the Buffer Vrefint for the COMP. |
mbed_official | 376:cb4d9db17537 | 616 | * @param NewState: new state of the Vrefint. |
mbed_official | 376:cb4d9db17537 | 617 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 376:cb4d9db17537 | 618 | * @note This is functional only if the LOCK is not set |
mbed_official | 376:cb4d9db17537 | 619 | * @retval None |
mbed_official | 376:cb4d9db17537 | 620 | */ |
mbed_official | 376:cb4d9db17537 | 621 | void HAL_COMP_EnableBuffer_Cmd(FunctionalState NewState) |
mbed_official | 376:cb4d9db17537 | 622 | { |
mbed_official | 376:cb4d9db17537 | 623 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 624 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 376:cb4d9db17537 | 625 | |
mbed_official | 376:cb4d9db17537 | 626 | if (NewState != DISABLE) |
mbed_official | 376:cb4d9db17537 | 627 | { |
mbed_official | 376:cb4d9db17537 | 628 | /* Enable the Buffer for the COMP by setting EN_VREFINT bit and the ENBUFLP_VREFINT_COMP in the CFGR3 register */ |
mbed_official | 376:cb4d9db17537 | 629 | SYSCFG->CFGR3 |= (SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP | SYSCFG_CFGR3_EN_VREFINT); |
mbed_official | 376:cb4d9db17537 | 630 | } |
mbed_official | 376:cb4d9db17537 | 631 | else |
mbed_official | 376:cb4d9db17537 | 632 | { |
mbed_official | 376:cb4d9db17537 | 633 | /* Disable the Vrefint by resetting ENBUFLP_BGAP_COMP bit and the EN_VREFINT bit in the CFGR3 register */ |
mbed_official | 376:cb4d9db17537 | 634 | SYSCFG->CFGR3 &= (uint32_t)~((uint32_t)(SYSCFG_CFGR3_ENBUFLP_VREFINT_COMP | SYSCFG_CFGR3_EN_VREFINT)); |
mbed_official | 376:cb4d9db17537 | 635 | } |
mbed_official | 376:cb4d9db17537 | 636 | } |
mbed_official | 376:cb4d9db17537 | 637 | |
mbed_official | 376:cb4d9db17537 | 638 | /** |
mbed_official | 376:cb4d9db17537 | 639 | * @brief Enables or disables the Buffer Vrefint for the RC48. |
mbed_official | 376:cb4d9db17537 | 640 | * @param NewState: new state of the Vrefint. |
mbed_official | 376:cb4d9db17537 | 641 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 376:cb4d9db17537 | 642 | * @note This is functional only if the LOCK is not set |
mbed_official | 376:cb4d9db17537 | 643 | * @retval None |
mbed_official | 376:cb4d9db17537 | 644 | */ |
mbed_official | 376:cb4d9db17537 | 645 | void HAL_RC48_EnableBuffer_Cmd(FunctionalState NewState) |
mbed_official | 376:cb4d9db17537 | 646 | { |
mbed_official | 376:cb4d9db17537 | 647 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 648 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 376:cb4d9db17537 | 649 | |
mbed_official | 376:cb4d9db17537 | 650 | if (NewState != DISABLE) |
mbed_official | 376:cb4d9db17537 | 651 | { |
mbed_official | 376:cb4d9db17537 | 652 | /* Enable the Buffer for the ADC by setting EN_VREFINT bit and the SYSCFG_CFGR3_ENREF_HSI48 in the CFGR3 register */ |
mbed_official | 376:cb4d9db17537 | 653 | SYSCFG->CFGR3 |= (SYSCFG_CFGR3_ENREF_HSI48 | SYSCFG_CFGR3_EN_VREFINT); |
mbed_official | 376:cb4d9db17537 | 654 | } |
mbed_official | 376:cb4d9db17537 | 655 | else |
mbed_official | 376:cb4d9db17537 | 656 | { |
mbed_official | 376:cb4d9db17537 | 657 | /* Disable the Vrefint by resetting SYSCFG_CFGR3_ENREF_HSI48 bit and the EN_VREFINT bit in the CFGR3 register */ |
mbed_official | 376:cb4d9db17537 | 658 | SYSCFG->CFGR3 &= (uint32_t)~((uint32_t)(SYSCFG_CFGR3_ENREF_HSI48 | SYSCFG_CFGR3_EN_VREFINT)); |
mbed_official | 376:cb4d9db17537 | 659 | } |
mbed_official | 376:cb4d9db17537 | 660 | } |
mbed_official | 376:cb4d9db17537 | 661 | |
mbed_official | 376:cb4d9db17537 | 662 | /** |
mbed_official | 376:cb4d9db17537 | 663 | * @brief Enables or disables the Lock. |
mbed_official | 376:cb4d9db17537 | 664 | * @param NewState: new state of the Lock. |
mbed_official | 376:cb4d9db17537 | 665 | * This parameter can be: ENABLE or DISABLE. |
mbed_official | 376:cb4d9db17537 | 666 | * @retval None |
mbed_official | 376:cb4d9db17537 | 667 | */ |
mbed_official | 376:cb4d9db17537 | 668 | void HAL_Lock_Cmd(FunctionalState NewState) |
mbed_official | 376:cb4d9db17537 | 669 | { |
mbed_official | 376:cb4d9db17537 | 670 | /* Check the parameters */ |
mbed_official | 376:cb4d9db17537 | 671 | assert_param(IS_FUNCTIONAL_STATE(NewState)); |
mbed_official | 376:cb4d9db17537 | 672 | |
mbed_official | 376:cb4d9db17537 | 673 | if (NewState != DISABLE) |
mbed_official | 376:cb4d9db17537 | 674 | { |
mbed_official | 376:cb4d9db17537 | 675 | /* Enable the LOCK by setting REF_LOCK bit in the CFGR3 register */ |
mbed_official | 376:cb4d9db17537 | 676 | SYSCFG->CFGR3 |= SYSCFG_CFGR3_REF_LOCK; |
mbed_official | 376:cb4d9db17537 | 677 | } |
mbed_official | 376:cb4d9db17537 | 678 | else |
mbed_official | 376:cb4d9db17537 | 679 | { |
mbed_official | 376:cb4d9db17537 | 680 | /* Disable the LOCK by setting REF_LOCK bit in the CFGR3 register */ |
mbed_official | 376:cb4d9db17537 | 681 | SYSCFG->CFGR3 &= (uint32_t)~((uint32_t)SYSCFG_CFGR3_REF_LOCK); |
mbed_official | 376:cb4d9db17537 | 682 | } |
mbed_official | 376:cb4d9db17537 | 683 | } |
mbed_official | 376:cb4d9db17537 | 684 | |
mbed_official | 376:cb4d9db17537 | 685 | /** |
mbed_official | 376:cb4d9db17537 | 686 | * @} |
mbed_official | 376:cb4d9db17537 | 687 | */ |
mbed_official | 376:cb4d9db17537 | 688 | |
mbed_official | 376:cb4d9db17537 | 689 | /** |
mbed_official | 376:cb4d9db17537 | 690 | * @} |
mbed_official | 376:cb4d9db17537 | 691 | */ |
mbed_official | 376:cb4d9db17537 | 692 | |
mbed_official | 376:cb4d9db17537 | 693 | #endif /* HAL_MODULE_ENABLED */ |
mbed_official | 376:cb4d9db17537 | 694 | /** |
mbed_official | 376:cb4d9db17537 | 695 | * @} |
mbed_official | 376:cb4d9db17537 | 696 | */ |
mbed_official | 376:cb4d9db17537 | 697 | |
mbed_official | 376:cb4d9db17537 | 698 | /** |
mbed_official | 376:cb4d9db17537 | 699 | * @} |
mbed_official | 376:cb4d9db17537 | 700 | */ |
mbed_official | 376:cb4d9db17537 | 701 | |
mbed_official | 376:cb4d9db17537 | 702 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |