L4 HAL Drivers
Src/stm32l4xx_hal.c@0:80ee8f3b695e, 2015-11-02 (annotated)
- Committer:
- EricLew
- Date:
- Mon Nov 02 19:37:23 2015 +0000
- Revision:
- 0:80ee8f3b695e
Errors are with definitions of LCD and QSPI functions. I believe all .h and .c files are uploaded, but there may need to be certain functions called.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
EricLew | 0:80ee8f3b695e | 1 | /** |
EricLew | 0:80ee8f3b695e | 2 | ****************************************************************************** |
EricLew | 0:80ee8f3b695e | 3 | * @file stm32l4xx_hal.c |
EricLew | 0:80ee8f3b695e | 4 | * @author MCD Application Team |
EricLew | 0:80ee8f3b695e | 5 | * @version V1.1.0 |
EricLew | 0:80ee8f3b695e | 6 | * @date 16-September-2015 |
EricLew | 0:80ee8f3b695e | 7 | * @brief HAL module driver. |
EricLew | 0:80ee8f3b695e | 8 | * This is the common part of the HAL initialization |
EricLew | 0:80ee8f3b695e | 9 | * |
EricLew | 0:80ee8f3b695e | 10 | @verbatim |
EricLew | 0:80ee8f3b695e | 11 | ============================================================================== |
EricLew | 0:80ee8f3b695e | 12 | ##### How to use this driver ##### |
EricLew | 0:80ee8f3b695e | 13 | ============================================================================== |
EricLew | 0:80ee8f3b695e | 14 | [..] |
EricLew | 0:80ee8f3b695e | 15 | The common HAL driver contains a set of generic and common APIs that can be |
EricLew | 0:80ee8f3b695e | 16 | used by the PPP peripheral drivers and the user to start using the HAL. |
EricLew | 0:80ee8f3b695e | 17 | [..] |
EricLew | 0:80ee8f3b695e | 18 | The HAL contains two APIs' categories: |
EricLew | 0:80ee8f3b695e | 19 | (+) Common HAL APIs |
EricLew | 0:80ee8f3b695e | 20 | (+) Services HAL APIs |
EricLew | 0:80ee8f3b695e | 21 | |
EricLew | 0:80ee8f3b695e | 22 | @endverbatim |
EricLew | 0:80ee8f3b695e | 23 | ****************************************************************************** |
EricLew | 0:80ee8f3b695e | 24 | * @attention |
EricLew | 0:80ee8f3b695e | 25 | * |
EricLew | 0:80ee8f3b695e | 26 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
EricLew | 0:80ee8f3b695e | 27 | * |
EricLew | 0:80ee8f3b695e | 28 | * Redistribution and use in source and binary forms, with or without modification, |
EricLew | 0:80ee8f3b695e | 29 | * are permitted provided that the following conditions are met: |
EricLew | 0:80ee8f3b695e | 30 | * 1. Redistributions of source code must retain the above copyright notice, |
EricLew | 0:80ee8f3b695e | 31 | * this list of conditions and the following disclaimer. |
EricLew | 0:80ee8f3b695e | 32 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
EricLew | 0:80ee8f3b695e | 33 | * this list of conditions and the following disclaimer in the documentation |
EricLew | 0:80ee8f3b695e | 34 | * and/or other materials provided with the distribution. |
EricLew | 0:80ee8f3b695e | 35 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
EricLew | 0:80ee8f3b695e | 36 | * may be used to endorse or promote products derived from this software |
EricLew | 0:80ee8f3b695e | 37 | * without specific prior written permission. |
EricLew | 0:80ee8f3b695e | 38 | * |
EricLew | 0:80ee8f3b695e | 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
EricLew | 0:80ee8f3b695e | 40 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
EricLew | 0:80ee8f3b695e | 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
EricLew | 0:80ee8f3b695e | 42 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
EricLew | 0:80ee8f3b695e | 43 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
EricLew | 0:80ee8f3b695e | 44 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
EricLew | 0:80ee8f3b695e | 45 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
EricLew | 0:80ee8f3b695e | 46 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
EricLew | 0:80ee8f3b695e | 47 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
EricLew | 0:80ee8f3b695e | 48 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
EricLew | 0:80ee8f3b695e | 49 | * |
EricLew | 0:80ee8f3b695e | 50 | ****************************************************************************** |
EricLew | 0:80ee8f3b695e | 51 | */ |
EricLew | 0:80ee8f3b695e | 52 | |
EricLew | 0:80ee8f3b695e | 53 | /* Includes ------------------------------------------------------------------*/ |
EricLew | 0:80ee8f3b695e | 54 | #include "stm32l4xx_hal.h" |
EricLew | 0:80ee8f3b695e | 55 | |
EricLew | 0:80ee8f3b695e | 56 | /** @addtogroup STM32L4xx_HAL_Driver |
EricLew | 0:80ee8f3b695e | 57 | * @{ |
EricLew | 0:80ee8f3b695e | 58 | */ |
EricLew | 0:80ee8f3b695e | 59 | |
EricLew | 0:80ee8f3b695e | 60 | /** @defgroup HAL HAL |
EricLew | 0:80ee8f3b695e | 61 | * @brief HAL module driver |
EricLew | 0:80ee8f3b695e | 62 | * @{ |
EricLew | 0:80ee8f3b695e | 63 | */ |
EricLew | 0:80ee8f3b695e | 64 | |
EricLew | 0:80ee8f3b695e | 65 | #ifdef HAL_MODULE_ENABLED |
EricLew | 0:80ee8f3b695e | 66 | |
EricLew | 0:80ee8f3b695e | 67 | /* Private typedef -----------------------------------------------------------*/ |
EricLew | 0:80ee8f3b695e | 68 | /* Private define ------------------------------------------------------------*/ |
EricLew | 0:80ee8f3b695e | 69 | /** |
EricLew | 0:80ee8f3b695e | 70 | * @brief STM32L4xx HAL Driver version number V1.1.0 |
EricLew | 0:80ee8f3b695e | 71 | */ |
EricLew | 0:80ee8f3b695e | 72 | #define __STM32L4xx_HAL_VERSION_MAIN (0x01) /*!< [31:24] main version */ |
EricLew | 0:80ee8f3b695e | 73 | #define __STM32L4xx_HAL_VERSION_SUB1 (0x01) /*!< [23:16] sub1 version */ |
EricLew | 0:80ee8f3b695e | 74 | #define __STM32L4xx_HAL_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */ |
EricLew | 0:80ee8f3b695e | 75 | #define __STM32L4xx_HAL_VERSION_RC (0x00) /*!< [7:0] release candidate */ |
EricLew | 0:80ee8f3b695e | 76 | #define __STM32L4xx_HAL_VERSION ((__STM32L4xx_HAL_VERSION_MAIN << 24)\ |
EricLew | 0:80ee8f3b695e | 77 | |(__STM32L4xx_HAL_VERSION_SUB1 << 16)\ |
EricLew | 0:80ee8f3b695e | 78 | |(__STM32L4xx_HAL_VERSION_SUB2 << 8 )\ |
EricLew | 0:80ee8f3b695e | 79 | |(__STM32L4xx_HAL_VERSION_RC)) |
EricLew | 0:80ee8f3b695e | 80 | |
EricLew | 0:80ee8f3b695e | 81 | #define VREFBUF_TIMEOUT_VALUE (uint32_t)10 /* 10 ms (to be confirmed) */ |
EricLew | 0:80ee8f3b695e | 82 | |
EricLew | 0:80ee8f3b695e | 83 | /* ------------ SYSCFG registers bit address in the alias region ------------ */ |
EricLew | 0:80ee8f3b695e | 84 | #define SYSCFG_OFFSET (SYSCFG_BASE - PERIPH_BASE) |
EricLew | 0:80ee8f3b695e | 85 | /* --- MEMRMP Register ---*/ |
EricLew | 0:80ee8f3b695e | 86 | /* Alias word address of FB_MODE bit */ |
EricLew | 0:80ee8f3b695e | 87 | #define MEMRMP_OFFSET SYSCFG_OFFSET |
EricLew | 0:80ee8f3b695e | 88 | #define FB_MODE_BitNumber ((uint8_t)0x8) |
EricLew | 0:80ee8f3b695e | 89 | #define FB_MODE_BB (PERIPH_BB_BASE + (MEMRMP_OFFSET * 32) + (FB_MODE_BitNumber * 4)) |
EricLew | 0:80ee8f3b695e | 90 | |
EricLew | 0:80ee8f3b695e | 91 | /* --- SCSR Register ---*/ |
EricLew | 0:80ee8f3b695e | 92 | /* Alias word address of SRAM2ER bit */ |
EricLew | 0:80ee8f3b695e | 93 | #define SCSR_OFFSET (SYSCFG_OFFSET + 0x18) |
EricLew | 0:80ee8f3b695e | 94 | #define BRER_BitNumber ((uint8_t)0x0) |
EricLew | 0:80ee8f3b695e | 95 | #define SCSR_SRAM2ER_BB (PERIPH_BB_BASE + (SCSR_OFFSET * 32) + (BRER_BitNumber * 4)) |
EricLew | 0:80ee8f3b695e | 96 | |
EricLew | 0:80ee8f3b695e | 97 | /* Private macro -------------------------------------------------------------*/ |
EricLew | 0:80ee8f3b695e | 98 | /* Private variables ---------------------------------------------------------*/ |
EricLew | 0:80ee8f3b695e | 99 | static __IO uint32_t uwTick; |
EricLew | 0:80ee8f3b695e | 100 | |
EricLew | 0:80ee8f3b695e | 101 | /* Private function prototypes -----------------------------------------------*/ |
EricLew | 0:80ee8f3b695e | 102 | /* Exported functions --------------------------------------------------------*/ |
EricLew | 0:80ee8f3b695e | 103 | |
EricLew | 0:80ee8f3b695e | 104 | /** @defgroup HAL_Exported_Functions HAL Exported Functions |
EricLew | 0:80ee8f3b695e | 105 | * @{ |
EricLew | 0:80ee8f3b695e | 106 | */ |
EricLew | 0:80ee8f3b695e | 107 | |
EricLew | 0:80ee8f3b695e | 108 | /** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions |
EricLew | 0:80ee8f3b695e | 109 | * @brief Initialization and de-initialization functions |
EricLew | 0:80ee8f3b695e | 110 | * |
EricLew | 0:80ee8f3b695e | 111 | @verbatim |
EricLew | 0:80ee8f3b695e | 112 | =============================================================================== |
EricLew | 0:80ee8f3b695e | 113 | ##### Initialization and de-initialization functions ##### |
EricLew | 0:80ee8f3b695e | 114 | =============================================================================== |
EricLew | 0:80ee8f3b695e | 115 | [..] This section provides functions allowing to: |
EricLew | 0:80ee8f3b695e | 116 | (+) Initialize the Flash interface the NVIC allocation and initial time base |
EricLew | 0:80ee8f3b695e | 117 | clock configuration. |
EricLew | 0:80ee8f3b695e | 118 | (+) De-initialize common part of the HAL. |
EricLew | 0:80ee8f3b695e | 119 | (+) Configure the time base source to have 1ms time base with a dedicated |
EricLew | 0:80ee8f3b695e | 120 | Tick interrupt priority. |
EricLew | 0:80ee8f3b695e | 121 | (++) SysTick timer is used by default as source of time base, but user |
EricLew | 0:80ee8f3b695e | 122 | can eventually implement his proper time base source (a general purpose |
EricLew | 0:80ee8f3b695e | 123 | timer for example or other time source), keeping in mind that Time base |
EricLew | 0:80ee8f3b695e | 124 | duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and |
EricLew | 0:80ee8f3b695e | 125 | handled in milliseconds basis. |
EricLew | 0:80ee8f3b695e | 126 | (++) Time base configuration function (HAL_InitTick ()) is called automatically |
EricLew | 0:80ee8f3b695e | 127 | at the beginning of the program after reset by HAL_Init() or at any time |
EricLew | 0:80ee8f3b695e | 128 | when clock is configured, by HAL_RCC_ClockConfig(). |
EricLew | 0:80ee8f3b695e | 129 | (++) Source of time base is configured to generate interrupts at regular |
EricLew | 0:80ee8f3b695e | 130 | time intervals. Care must be taken if HAL_Delay() is called from a |
EricLew | 0:80ee8f3b695e | 131 | peripheral ISR process, the Tick interrupt line must have higher priority |
EricLew | 0:80ee8f3b695e | 132 | (numerically lower) than the peripheral interrupt. Otherwise the caller |
EricLew | 0:80ee8f3b695e | 133 | ISR process will be blocked. |
EricLew | 0:80ee8f3b695e | 134 | (++) functions affecting time base configurations are declared as __weak |
EricLew | 0:80ee8f3b695e | 135 | to make override possible in case of other implementations in user file. |
EricLew | 0:80ee8f3b695e | 136 | @endverbatim |
EricLew | 0:80ee8f3b695e | 137 | * @{ |
EricLew | 0:80ee8f3b695e | 138 | */ |
EricLew | 0:80ee8f3b695e | 139 | |
EricLew | 0:80ee8f3b695e | 140 | /** |
EricLew | 0:80ee8f3b695e | 141 | * @brief Configure the Flash prefetch, the Instruction and Data caches, |
EricLew | 0:80ee8f3b695e | 142 | * the time base source, NVIC and any required global low level hardware |
EricLew | 0:80ee8f3b695e | 143 | * by calling the HAL_MspInit() callback function to be optionally defined in user file |
EricLew | 0:80ee8f3b695e | 144 | * stm32l4xx_hal_msp.c. |
EricLew | 0:80ee8f3b695e | 145 | * |
EricLew | 0:80ee8f3b695e | 146 | * @note HAL_Init() function is called at the beginning of program after reset and before |
EricLew | 0:80ee8f3b695e | 147 | * the clock configuration. |
EricLew | 0:80ee8f3b695e | 148 | * |
EricLew | 0:80ee8f3b695e | 149 | * @note In the default implementation the System Timer (Systick) is used as source of time base. |
EricLew | 0:80ee8f3b695e | 150 | * The Systick configuration is based on MSI clock, as MSI is the clock |
EricLew | 0:80ee8f3b695e | 151 | * used after a system Reset and the NVIC configuration is set to Priority group 4. |
EricLew | 0:80ee8f3b695e | 152 | * Once done, time base tick starts incrementing: the tick variable counter is incremented |
EricLew | 0:80ee8f3b695e | 153 | * each 1ms in the SysTick_Handler() interrupt handler. |
EricLew | 0:80ee8f3b695e | 154 | * |
EricLew | 0:80ee8f3b695e | 155 | * @retval HAL status |
EricLew | 0:80ee8f3b695e | 156 | */ |
EricLew | 0:80ee8f3b695e | 157 | HAL_StatusTypeDef HAL_Init(void) |
EricLew | 0:80ee8f3b695e | 158 | { |
EricLew | 0:80ee8f3b695e | 159 | /* Configure Flash prefetch, Instruction cache, Data cache */ |
EricLew | 0:80ee8f3b695e | 160 | /* Default configuration at reset is: */ |
EricLew | 0:80ee8f3b695e | 161 | /* - Prefetch disabled */ |
EricLew | 0:80ee8f3b695e | 162 | /* - Instruction cache enabled */ |
EricLew | 0:80ee8f3b695e | 163 | /* - Data cache enabled */ |
EricLew | 0:80ee8f3b695e | 164 | #if (INSTRUCTION_CACHE_ENABLE == 0) |
EricLew | 0:80ee8f3b695e | 165 | __HAL_FLASH_INSTRUCTION_CACHE_DISABLE(); |
EricLew | 0:80ee8f3b695e | 166 | #endif /* INSTRUCTION_CACHE_ENABLE */ |
EricLew | 0:80ee8f3b695e | 167 | |
EricLew | 0:80ee8f3b695e | 168 | #if (DATA_CACHE_ENABLE == 0) |
EricLew | 0:80ee8f3b695e | 169 | __HAL_FLASH_DATA_CACHE_DISABLE(); |
EricLew | 0:80ee8f3b695e | 170 | #endif /* DATA_CACHE_ENABLE */ |
EricLew | 0:80ee8f3b695e | 171 | |
EricLew | 0:80ee8f3b695e | 172 | #if (PREFETCH_ENABLE != 0) |
EricLew | 0:80ee8f3b695e | 173 | __HAL_FLASH_PREFETCH_BUFFER_ENABLE(); |
EricLew | 0:80ee8f3b695e | 174 | #endif /* PREFETCH_ENABLE */ |
EricLew | 0:80ee8f3b695e | 175 | |
EricLew | 0:80ee8f3b695e | 176 | /* Set Interrupt Group Priority */ |
EricLew | 0:80ee8f3b695e | 177 | HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); |
EricLew | 0:80ee8f3b695e | 178 | |
EricLew | 0:80ee8f3b695e | 179 | /* Use SysTick as time base source and configure 1ms tick (default clock after Reset is MSI) */ |
EricLew | 0:80ee8f3b695e | 180 | HAL_InitTick(TICK_INT_PRIORITY); |
EricLew | 0:80ee8f3b695e | 181 | |
EricLew | 0:80ee8f3b695e | 182 | /* Init the low level hardware */ |
EricLew | 0:80ee8f3b695e | 183 | HAL_MspInit(); |
EricLew | 0:80ee8f3b695e | 184 | |
EricLew | 0:80ee8f3b695e | 185 | /* Return function status */ |
EricLew | 0:80ee8f3b695e | 186 | return HAL_OK; |
EricLew | 0:80ee8f3b695e | 187 | } |
EricLew | 0:80ee8f3b695e | 188 | |
EricLew | 0:80ee8f3b695e | 189 | /** |
EricLew | 0:80ee8f3b695e | 190 | * @brief De-initialize common part of the HAL and stop the source of time base. |
EricLew | 0:80ee8f3b695e | 191 | * @note This function is optional. |
EricLew | 0:80ee8f3b695e | 192 | * @retval HAL status |
EricLew | 0:80ee8f3b695e | 193 | */ |
EricLew | 0:80ee8f3b695e | 194 | HAL_StatusTypeDef HAL_DeInit(void) |
EricLew | 0:80ee8f3b695e | 195 | { |
EricLew | 0:80ee8f3b695e | 196 | /* Reset of all peripherals */ |
EricLew | 0:80ee8f3b695e | 197 | __HAL_RCC_APB1_FORCE_RESET(); |
EricLew | 0:80ee8f3b695e | 198 | __HAL_RCC_APB1_RELEASE_RESET(); |
EricLew | 0:80ee8f3b695e | 199 | |
EricLew | 0:80ee8f3b695e | 200 | __HAL_RCC_APB2_FORCE_RESET(); |
EricLew | 0:80ee8f3b695e | 201 | __HAL_RCC_APB2_RELEASE_RESET(); |
EricLew | 0:80ee8f3b695e | 202 | |
EricLew | 0:80ee8f3b695e | 203 | __HAL_RCC_AHB1_FORCE_RESET(); |
EricLew | 0:80ee8f3b695e | 204 | __HAL_RCC_AHB1_RELEASE_RESET(); |
EricLew | 0:80ee8f3b695e | 205 | |
EricLew | 0:80ee8f3b695e | 206 | __HAL_RCC_AHB2_FORCE_RESET(); |
EricLew | 0:80ee8f3b695e | 207 | __HAL_RCC_AHB2_RELEASE_RESET(); |
EricLew | 0:80ee8f3b695e | 208 | |
EricLew | 0:80ee8f3b695e | 209 | __HAL_RCC_AHB3_FORCE_RESET(); |
EricLew | 0:80ee8f3b695e | 210 | __HAL_RCC_AHB3_RELEASE_RESET(); |
EricLew | 0:80ee8f3b695e | 211 | |
EricLew | 0:80ee8f3b695e | 212 | /* De-Init the low level hardware */ |
EricLew | 0:80ee8f3b695e | 213 | HAL_MspDeInit(); |
EricLew | 0:80ee8f3b695e | 214 | |
EricLew | 0:80ee8f3b695e | 215 | /* Return function status */ |
EricLew | 0:80ee8f3b695e | 216 | return HAL_OK; |
EricLew | 0:80ee8f3b695e | 217 | } |
EricLew | 0:80ee8f3b695e | 218 | |
EricLew | 0:80ee8f3b695e | 219 | /** |
EricLew | 0:80ee8f3b695e | 220 | * @brief Initialize the MSP. |
EricLew | 0:80ee8f3b695e | 221 | * @retval None |
EricLew | 0:80ee8f3b695e | 222 | */ |
EricLew | 0:80ee8f3b695e | 223 | __weak void HAL_MspInit(void) |
EricLew | 0:80ee8f3b695e | 224 | { |
EricLew | 0:80ee8f3b695e | 225 | /* NOTE : This function should not be modified, when the callback is needed, |
EricLew | 0:80ee8f3b695e | 226 | the HAL_MspInit could be implemented in the user file |
EricLew | 0:80ee8f3b695e | 227 | */ |
EricLew | 0:80ee8f3b695e | 228 | } |
EricLew | 0:80ee8f3b695e | 229 | |
EricLew | 0:80ee8f3b695e | 230 | /** |
EricLew | 0:80ee8f3b695e | 231 | * @brief DeInitialize the MSP. |
EricLew | 0:80ee8f3b695e | 232 | * @retval None |
EricLew | 0:80ee8f3b695e | 233 | */ |
EricLew | 0:80ee8f3b695e | 234 | __weak void HAL_MspDeInit(void) |
EricLew | 0:80ee8f3b695e | 235 | { |
EricLew | 0:80ee8f3b695e | 236 | /* NOTE : This function should not be modified, when the callback is needed, |
EricLew | 0:80ee8f3b695e | 237 | the HAL_MspDeInit could be implemented in the user file |
EricLew | 0:80ee8f3b695e | 238 | */ |
EricLew | 0:80ee8f3b695e | 239 | } |
EricLew | 0:80ee8f3b695e | 240 | |
EricLew | 0:80ee8f3b695e | 241 | /** |
EricLew | 0:80ee8f3b695e | 242 | * @brief This function configures the source of the time base: |
EricLew | 0:80ee8f3b695e | 243 | * The time source is configured to have 1ms time base with a dedicated |
EricLew | 0:80ee8f3b695e | 244 | * Tick interrupt priority. |
EricLew | 0:80ee8f3b695e | 245 | * @note This function is called automatically at the beginning of program after |
EricLew | 0:80ee8f3b695e | 246 | * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig(). |
EricLew | 0:80ee8f3b695e | 247 | * @note In the default implementation, SysTick timer is the source of time base. |
EricLew | 0:80ee8f3b695e | 248 | * It is used to generate interrupts at regular time intervals. |
EricLew | 0:80ee8f3b695e | 249 | * Care must be taken if HAL_Delay() is called from a peripheral ISR process, |
EricLew | 0:80ee8f3b695e | 250 | * The SysTick interrupt must have higher priority (numerically lower) |
EricLew | 0:80ee8f3b695e | 251 | * than the peripheral interrupt. Otherwise the caller ISR process will be blocked. |
EricLew | 0:80ee8f3b695e | 252 | * The function is declared as __weak to be overwritten in case of other |
EricLew | 0:80ee8f3b695e | 253 | * implementation in user file. |
EricLew | 0:80ee8f3b695e | 254 | * @param TickPriority: Tick interrupt priority. |
EricLew | 0:80ee8f3b695e | 255 | * @retval HAL status |
EricLew | 0:80ee8f3b695e | 256 | */ |
EricLew | 0:80ee8f3b695e | 257 | __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) |
EricLew | 0:80ee8f3b695e | 258 | { |
EricLew | 0:80ee8f3b695e | 259 | /*Configure the SysTick to have interrupt in 1ms time basis*/ |
EricLew | 0:80ee8f3b695e | 260 | HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); |
EricLew | 0:80ee8f3b695e | 261 | |
EricLew | 0:80ee8f3b695e | 262 | /*Configure the SysTick IRQ priority */ |
EricLew | 0:80ee8f3b695e | 263 | HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0); |
EricLew | 0:80ee8f3b695e | 264 | |
EricLew | 0:80ee8f3b695e | 265 | /* Return function status */ |
EricLew | 0:80ee8f3b695e | 266 | return HAL_OK; |
EricLew | 0:80ee8f3b695e | 267 | } |
EricLew | 0:80ee8f3b695e | 268 | |
EricLew | 0:80ee8f3b695e | 269 | /** |
EricLew | 0:80ee8f3b695e | 270 | * @} |
EricLew | 0:80ee8f3b695e | 271 | */ |
EricLew | 0:80ee8f3b695e | 272 | |
EricLew | 0:80ee8f3b695e | 273 | /** @defgroup HAL_Exported_Functions_Group2 HAL Control functions |
EricLew | 0:80ee8f3b695e | 274 | * @brief HAL Control functions |
EricLew | 0:80ee8f3b695e | 275 | * |
EricLew | 0:80ee8f3b695e | 276 | @verbatim |
EricLew | 0:80ee8f3b695e | 277 | =============================================================================== |
EricLew | 0:80ee8f3b695e | 278 | ##### HAL Control functions ##### |
EricLew | 0:80ee8f3b695e | 279 | =============================================================================== |
EricLew | 0:80ee8f3b695e | 280 | [..] This section provides functions allowing to: |
EricLew | 0:80ee8f3b695e | 281 | (+) Provide a tick value in millisecond |
EricLew | 0:80ee8f3b695e | 282 | (+) Provide a blocking delay in millisecond |
EricLew | 0:80ee8f3b695e | 283 | (+) Suspend the time base source interrupt |
EricLew | 0:80ee8f3b695e | 284 | (+) Resume the time base source interrupt |
EricLew | 0:80ee8f3b695e | 285 | (+) Get the HAL API driver version |
EricLew | 0:80ee8f3b695e | 286 | (+) Get the device identifier |
EricLew | 0:80ee8f3b695e | 287 | (+) Get the device revision identifier |
EricLew | 0:80ee8f3b695e | 288 | |
EricLew | 0:80ee8f3b695e | 289 | @endverbatim |
EricLew | 0:80ee8f3b695e | 290 | * @{ |
EricLew | 0:80ee8f3b695e | 291 | */ |
EricLew | 0:80ee8f3b695e | 292 | |
EricLew | 0:80ee8f3b695e | 293 | /** |
EricLew | 0:80ee8f3b695e | 294 | * @brief This function is called to increment a global variable "uwTick" |
EricLew | 0:80ee8f3b695e | 295 | * used as application time base. |
EricLew | 0:80ee8f3b695e | 296 | * @note In the default implementation, this variable is incremented each 1ms |
EricLew | 0:80ee8f3b695e | 297 | * in SysTick ISR. |
EricLew | 0:80ee8f3b695e | 298 | * @note This function is declared as __weak to be overwritten in case of other |
EricLew | 0:80ee8f3b695e | 299 | * implementations in user file. |
EricLew | 0:80ee8f3b695e | 300 | * @retval None |
EricLew | 0:80ee8f3b695e | 301 | */ |
EricLew | 0:80ee8f3b695e | 302 | __weak void HAL_IncTick(void) |
EricLew | 0:80ee8f3b695e | 303 | { |
EricLew | 0:80ee8f3b695e | 304 | uwTick++; |
EricLew | 0:80ee8f3b695e | 305 | } |
EricLew | 0:80ee8f3b695e | 306 | |
EricLew | 0:80ee8f3b695e | 307 | /** |
EricLew | 0:80ee8f3b695e | 308 | * @brief Provide a tick value in millisecond. |
EricLew | 0:80ee8f3b695e | 309 | * @note This function is declared as __weak to be overwritten in case of other |
EricLew | 0:80ee8f3b695e | 310 | * implementations in user file. |
EricLew | 0:80ee8f3b695e | 311 | * @retval tick value |
EricLew | 0:80ee8f3b695e | 312 | */ |
EricLew | 0:80ee8f3b695e | 313 | __weak uint32_t HAL_GetTick(void) |
EricLew | 0:80ee8f3b695e | 314 | { |
EricLew | 0:80ee8f3b695e | 315 | return uwTick; |
EricLew | 0:80ee8f3b695e | 316 | } |
EricLew | 0:80ee8f3b695e | 317 | |
EricLew | 0:80ee8f3b695e | 318 | /** |
EricLew | 0:80ee8f3b695e | 319 | * @brief Provide accurate delay (in milliseconds) based on variable incremented. |
EricLew | 0:80ee8f3b695e | 320 | * @note In the default implementation , SysTick timer is the source of time base. |
EricLew | 0:80ee8f3b695e | 321 | * It is used to generate interrupts at regular time intervals where uwTick |
EricLew | 0:80ee8f3b695e | 322 | * is incremented. |
EricLew | 0:80ee8f3b695e | 323 | * @note This function is declared as __weak to be overwritten in case of other |
EricLew | 0:80ee8f3b695e | 324 | * implementations in user file. |
EricLew | 0:80ee8f3b695e | 325 | * @param Delay: specifies the delay time length, in milliseconds. |
EricLew | 0:80ee8f3b695e | 326 | * @retval None |
EricLew | 0:80ee8f3b695e | 327 | */ |
EricLew | 0:80ee8f3b695e | 328 | __weak void HAL_Delay(uint32_t Delay) |
EricLew | 0:80ee8f3b695e | 329 | { |
EricLew | 0:80ee8f3b695e | 330 | uint32_t tickstart = 0; |
EricLew | 0:80ee8f3b695e | 331 | tickstart = HAL_GetTick(); |
EricLew | 0:80ee8f3b695e | 332 | while((HAL_GetTick() - tickstart) < Delay) |
EricLew | 0:80ee8f3b695e | 333 | { |
EricLew | 0:80ee8f3b695e | 334 | } |
EricLew | 0:80ee8f3b695e | 335 | } |
EricLew | 0:80ee8f3b695e | 336 | |
EricLew | 0:80ee8f3b695e | 337 | /** |
EricLew | 0:80ee8f3b695e | 338 | * @brief Suspend Tick increment. |
EricLew | 0:80ee8f3b695e | 339 | * @note In the default implementation , SysTick timer is the source of time base. It is |
EricLew | 0:80ee8f3b695e | 340 | * used to generate interrupts at regular time intervals. Once HAL_SuspendTick() |
EricLew | 0:80ee8f3b695e | 341 | * is called, the SysTick interrupt will be disabled and so Tick increment |
EricLew | 0:80ee8f3b695e | 342 | * is suspended. |
EricLew | 0:80ee8f3b695e | 343 | * @note This function is declared as __weak to be overwritten in case of other |
EricLew | 0:80ee8f3b695e | 344 | * implementations in user file. |
EricLew | 0:80ee8f3b695e | 345 | * @retval None |
EricLew | 0:80ee8f3b695e | 346 | */ |
EricLew | 0:80ee8f3b695e | 347 | __weak void HAL_SuspendTick(void) |
EricLew | 0:80ee8f3b695e | 348 | { |
EricLew | 0:80ee8f3b695e | 349 | /* Disable SysTick Interrupt */ |
EricLew | 0:80ee8f3b695e | 350 | SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; |
EricLew | 0:80ee8f3b695e | 351 | } |
EricLew | 0:80ee8f3b695e | 352 | |
EricLew | 0:80ee8f3b695e | 353 | /** |
EricLew | 0:80ee8f3b695e | 354 | * @brief Resume Tick increment. |
EricLew | 0:80ee8f3b695e | 355 | * @note In the default implementation , SysTick timer is the source of time base. It is |
EricLew | 0:80ee8f3b695e | 356 | * used to generate interrupts at regular time intervals. Once HAL_ResumeTick() |
EricLew | 0:80ee8f3b695e | 357 | * is called, the SysTick interrupt will be enabled and so Tick increment |
EricLew | 0:80ee8f3b695e | 358 | * is resumed. |
EricLew | 0:80ee8f3b695e | 359 | * @note This function is declared as __weak to be overwritten in case of other |
EricLew | 0:80ee8f3b695e | 360 | * implementations in user file. |
EricLew | 0:80ee8f3b695e | 361 | * @retval None |
EricLew | 0:80ee8f3b695e | 362 | */ |
EricLew | 0:80ee8f3b695e | 363 | __weak void HAL_ResumeTick(void) |
EricLew | 0:80ee8f3b695e | 364 | { |
EricLew | 0:80ee8f3b695e | 365 | /* Enable SysTick Interrupt */ |
EricLew | 0:80ee8f3b695e | 366 | SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; |
EricLew | 0:80ee8f3b695e | 367 | } |
EricLew | 0:80ee8f3b695e | 368 | |
EricLew | 0:80ee8f3b695e | 369 | /** |
EricLew | 0:80ee8f3b695e | 370 | * @brief Return the HAL revision. |
EricLew | 0:80ee8f3b695e | 371 | * @retval version : 0xXYZR (8bits for each decimal, R for RC) |
EricLew | 0:80ee8f3b695e | 372 | */ |
EricLew | 0:80ee8f3b695e | 373 | uint32_t HAL_GetHalVersion(void) |
EricLew | 0:80ee8f3b695e | 374 | { |
EricLew | 0:80ee8f3b695e | 375 | return __STM32L4xx_HAL_VERSION; |
EricLew | 0:80ee8f3b695e | 376 | } |
EricLew | 0:80ee8f3b695e | 377 | |
EricLew | 0:80ee8f3b695e | 378 | /** |
EricLew | 0:80ee8f3b695e | 379 | * @brief Return the device revision identifier. |
EricLew | 0:80ee8f3b695e | 380 | * @retval Device revision identifier |
EricLew | 0:80ee8f3b695e | 381 | */ |
EricLew | 0:80ee8f3b695e | 382 | uint32_t HAL_GetREVID(void) |
EricLew | 0:80ee8f3b695e | 383 | { |
EricLew | 0:80ee8f3b695e | 384 | return((DBGMCU->IDCODE & DBGMCU_IDCODE_REV_ID) >> 16); |
EricLew | 0:80ee8f3b695e | 385 | } |
EricLew | 0:80ee8f3b695e | 386 | |
EricLew | 0:80ee8f3b695e | 387 | /** |
EricLew | 0:80ee8f3b695e | 388 | * @brief Return the device identifier. |
EricLew | 0:80ee8f3b695e | 389 | * @retval Device identifier |
EricLew | 0:80ee8f3b695e | 390 | */ |
EricLew | 0:80ee8f3b695e | 391 | uint32_t HAL_GetDEVID(void) |
EricLew | 0:80ee8f3b695e | 392 | { |
EricLew | 0:80ee8f3b695e | 393 | return(DBGMCU->IDCODE & DBGMCU_IDCODE_DEV_ID); |
EricLew | 0:80ee8f3b695e | 394 | } |
EricLew | 0:80ee8f3b695e | 395 | |
EricLew | 0:80ee8f3b695e | 396 | /** |
EricLew | 0:80ee8f3b695e | 397 | * @} |
EricLew | 0:80ee8f3b695e | 398 | */ |
EricLew | 0:80ee8f3b695e | 399 | |
EricLew | 0:80ee8f3b695e | 400 | /** @defgroup HAL_Exported_Functions_Group3 HAL Debug functions |
EricLew | 0:80ee8f3b695e | 401 | * @brief HAL Debug functions |
EricLew | 0:80ee8f3b695e | 402 | * |
EricLew | 0:80ee8f3b695e | 403 | @verbatim |
EricLew | 0:80ee8f3b695e | 404 | =============================================================================== |
EricLew | 0:80ee8f3b695e | 405 | ##### HAL Debug functions ##### |
EricLew | 0:80ee8f3b695e | 406 | =============================================================================== |
EricLew | 0:80ee8f3b695e | 407 | [..] This section provides functions allowing to: |
EricLew | 0:80ee8f3b695e | 408 | (+) Enable/Disable Debug module during SLEEP mode |
EricLew | 0:80ee8f3b695e | 409 | (+) Enable/Disable Debug module during STOP1/STOP2 modes |
EricLew | 0:80ee8f3b695e | 410 | (+) Enable/Disable Debug module during STANDBY mode |
EricLew | 0:80ee8f3b695e | 411 | |
EricLew | 0:80ee8f3b695e | 412 | @endverbatim |
EricLew | 0:80ee8f3b695e | 413 | * @{ |
EricLew | 0:80ee8f3b695e | 414 | */ |
EricLew | 0:80ee8f3b695e | 415 | |
EricLew | 0:80ee8f3b695e | 416 | /** |
EricLew | 0:80ee8f3b695e | 417 | * @brief Enable the Debug Module during SLEEP mode. |
EricLew | 0:80ee8f3b695e | 418 | * @retval None |
EricLew | 0:80ee8f3b695e | 419 | */ |
EricLew | 0:80ee8f3b695e | 420 | void HAL_DBGMCU_EnableDBGSleepMode(void) |
EricLew | 0:80ee8f3b695e | 421 | { |
EricLew | 0:80ee8f3b695e | 422 | SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); |
EricLew | 0:80ee8f3b695e | 423 | } |
EricLew | 0:80ee8f3b695e | 424 | |
EricLew | 0:80ee8f3b695e | 425 | /** |
EricLew | 0:80ee8f3b695e | 426 | * @brief Disable the Debug Module during SLEEP mode. |
EricLew | 0:80ee8f3b695e | 427 | * @retval None |
EricLew | 0:80ee8f3b695e | 428 | */ |
EricLew | 0:80ee8f3b695e | 429 | void HAL_DBGMCU_DisableDBGSleepMode(void) |
EricLew | 0:80ee8f3b695e | 430 | { |
EricLew | 0:80ee8f3b695e | 431 | CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); |
EricLew | 0:80ee8f3b695e | 432 | } |
EricLew | 0:80ee8f3b695e | 433 | |
EricLew | 0:80ee8f3b695e | 434 | /** |
EricLew | 0:80ee8f3b695e | 435 | * @brief Enable the Debug Module during STOP1/STOP2 modes. |
EricLew | 0:80ee8f3b695e | 436 | * @retval None |
EricLew | 0:80ee8f3b695e | 437 | */ |
EricLew | 0:80ee8f3b695e | 438 | void HAL_DBGMCU_EnableDBGStopMode(void) |
EricLew | 0:80ee8f3b695e | 439 | { |
EricLew | 0:80ee8f3b695e | 440 | SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); |
EricLew | 0:80ee8f3b695e | 441 | } |
EricLew | 0:80ee8f3b695e | 442 | |
EricLew | 0:80ee8f3b695e | 443 | /** |
EricLew | 0:80ee8f3b695e | 444 | * @brief Disable the Debug Module during STOP1/STOP2 modes. |
EricLew | 0:80ee8f3b695e | 445 | * @retval None |
EricLew | 0:80ee8f3b695e | 446 | */ |
EricLew | 0:80ee8f3b695e | 447 | void HAL_DBGMCU_DisableDBGStopMode(void) |
EricLew | 0:80ee8f3b695e | 448 | { |
EricLew | 0:80ee8f3b695e | 449 | CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); |
EricLew | 0:80ee8f3b695e | 450 | } |
EricLew | 0:80ee8f3b695e | 451 | |
EricLew | 0:80ee8f3b695e | 452 | /** |
EricLew | 0:80ee8f3b695e | 453 | * @brief Enable the Debug Module during STANDBY mode. |
EricLew | 0:80ee8f3b695e | 454 | * @retval None |
EricLew | 0:80ee8f3b695e | 455 | */ |
EricLew | 0:80ee8f3b695e | 456 | void HAL_DBGMCU_EnableDBGStandbyMode(void) |
EricLew | 0:80ee8f3b695e | 457 | { |
EricLew | 0:80ee8f3b695e | 458 | SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); |
EricLew | 0:80ee8f3b695e | 459 | } |
EricLew | 0:80ee8f3b695e | 460 | |
EricLew | 0:80ee8f3b695e | 461 | /** |
EricLew | 0:80ee8f3b695e | 462 | * @brief Disable the Debug Module during STANDBY mode. |
EricLew | 0:80ee8f3b695e | 463 | * @retval None |
EricLew | 0:80ee8f3b695e | 464 | */ |
EricLew | 0:80ee8f3b695e | 465 | void HAL_DBGMCU_DisableDBGStandbyMode(void) |
EricLew | 0:80ee8f3b695e | 466 | { |
EricLew | 0:80ee8f3b695e | 467 | CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); |
EricLew | 0:80ee8f3b695e | 468 | } |
EricLew | 0:80ee8f3b695e | 469 | |
EricLew | 0:80ee8f3b695e | 470 | /** |
EricLew | 0:80ee8f3b695e | 471 | * @} |
EricLew | 0:80ee8f3b695e | 472 | */ |
EricLew | 0:80ee8f3b695e | 473 | |
EricLew | 0:80ee8f3b695e | 474 | /** @defgroup HAL_Exported_Functions_Group4 HAL SYSCFG configuration functions |
EricLew | 0:80ee8f3b695e | 475 | * @brief HAL SYSCFG configuration functions |
EricLew | 0:80ee8f3b695e | 476 | * |
EricLew | 0:80ee8f3b695e | 477 | @verbatim |
EricLew | 0:80ee8f3b695e | 478 | =============================================================================== |
EricLew | 0:80ee8f3b695e | 479 | ##### HAL SYSCFG configuration functions ##### |
EricLew | 0:80ee8f3b695e | 480 | =============================================================================== |
EricLew | 0:80ee8f3b695e | 481 | [..] This section provides functions allowing to: |
EricLew | 0:80ee8f3b695e | 482 | (+) Start a hardware SRAM2 erase operation |
EricLew | 0:80ee8f3b695e | 483 | (+) Enable/Disable the Internal FLASH Bank Swapping |
EricLew | 0:80ee8f3b695e | 484 | (+) Configure the Voltage reference buffer |
EricLew | 0:80ee8f3b695e | 485 | (+) Enable/Disable the Voltage reference buffer |
EricLew | 0:80ee8f3b695e | 486 | |
EricLew | 0:80ee8f3b695e | 487 | @endverbatim |
EricLew | 0:80ee8f3b695e | 488 | * @{ |
EricLew | 0:80ee8f3b695e | 489 | */ |
EricLew | 0:80ee8f3b695e | 490 | |
EricLew | 0:80ee8f3b695e | 491 | /** |
EricLew | 0:80ee8f3b695e | 492 | * @brief Start a hardware SRAM2 erase operation. |
EricLew | 0:80ee8f3b695e | 493 | * @note As long as SRAM2 is not erased the SRAM2ER bit will be set. |
EricLew | 0:80ee8f3b695e | 494 | * This bit is automatically reset at the end of the SRAM2 erase operation. |
EricLew | 0:80ee8f3b695e | 495 | * @retval None |
EricLew | 0:80ee8f3b695e | 496 | */ |
EricLew | 0:80ee8f3b695e | 497 | void HAL_SYSCFG_SRAM2Erase(void) |
EricLew | 0:80ee8f3b695e | 498 | { |
EricLew | 0:80ee8f3b695e | 499 | /* unlock the write protection of the SRAM2ER bit */ |
EricLew | 0:80ee8f3b695e | 500 | SYSCFG->SKR = 0xCA; |
EricLew | 0:80ee8f3b695e | 501 | SYSCFG->SKR = 0x53; |
EricLew | 0:80ee8f3b695e | 502 | /* Starts a hardware SRAM2 erase operation*/ |
EricLew | 0:80ee8f3b695e | 503 | *(__IO uint32_t *) SCSR_SRAM2ER_BB = (uint8_t)0x00000001; |
EricLew | 0:80ee8f3b695e | 504 | } |
EricLew | 0:80ee8f3b695e | 505 | |
EricLew | 0:80ee8f3b695e | 506 | /** |
EricLew | 0:80ee8f3b695e | 507 | * @brief Enable the Internal FLASH Bank Swapping. |
EricLew | 0:80ee8f3b695e | 508 | * |
EricLew | 0:80ee8f3b695e | 509 | * @note This function can be used only for STM32L4xx devices. |
EricLew | 0:80ee8f3b695e | 510 | * |
EricLew | 0:80ee8f3b695e | 511 | * @note Flash Bank2 mapped at 0x08000000 (and aliased @0x00000000) |
EricLew | 0:80ee8f3b695e | 512 | * and Flash Bank1 mapped at 0x08100000 (and aliased at 0x00100000) |
EricLew | 0:80ee8f3b695e | 513 | * |
EricLew | 0:80ee8f3b695e | 514 | * @retval None |
EricLew | 0:80ee8f3b695e | 515 | */ |
EricLew | 0:80ee8f3b695e | 516 | void HAL_SYSCFG_EnableMemorySwappingBank(void) |
EricLew | 0:80ee8f3b695e | 517 | { |
EricLew | 0:80ee8f3b695e | 518 | *(__IO uint32_t *)FB_MODE_BB = (uint32_t)ENABLE; |
EricLew | 0:80ee8f3b695e | 519 | } |
EricLew | 0:80ee8f3b695e | 520 | |
EricLew | 0:80ee8f3b695e | 521 | /** |
EricLew | 0:80ee8f3b695e | 522 | * @brief Disable the Internal FLASH Bank Swapping. |
EricLew | 0:80ee8f3b695e | 523 | * |
EricLew | 0:80ee8f3b695e | 524 | * @note This function can be used only for STM32L4xx devices. |
EricLew | 0:80ee8f3b695e | 525 | * |
EricLew | 0:80ee8f3b695e | 526 | * @note The default state : Flash Bank1 mapped at 0x08000000 (and aliased @0x0000 0000) |
EricLew | 0:80ee8f3b695e | 527 | * and Flash Bank2 mapped at 0x08100000 (and aliased at 0x00100000) |
EricLew | 0:80ee8f3b695e | 528 | * |
EricLew | 0:80ee8f3b695e | 529 | * @retval None |
EricLew | 0:80ee8f3b695e | 530 | */ |
EricLew | 0:80ee8f3b695e | 531 | void HAL_SYSCFG_DisableMemorySwappingBank(void) |
EricLew | 0:80ee8f3b695e | 532 | { |
EricLew | 0:80ee8f3b695e | 533 | |
EricLew | 0:80ee8f3b695e | 534 | *(__IO uint32_t *)FB_MODE_BB = (uint32_t)DISABLE; |
EricLew | 0:80ee8f3b695e | 535 | } |
EricLew | 0:80ee8f3b695e | 536 | |
EricLew | 0:80ee8f3b695e | 537 | /** |
EricLew | 0:80ee8f3b695e | 538 | * @brief Configure the internal voltage reference buffer voltage scale. |
EricLew | 0:80ee8f3b695e | 539 | * @param VoltageScaling: specifies the output voltage to achieve |
EricLew | 0:80ee8f3b695e | 540 | * This parameter can be one of the following values: |
EricLew | 0:80ee8f3b695e | 541 | * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE0: VREF_OUT1 around 2.048 V. |
EricLew | 0:80ee8f3b695e | 542 | * This requires VDDA equal to or higher than 2.4 V. |
EricLew | 0:80ee8f3b695e | 543 | * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE1: VREF_OUT1 around 2.5 V. |
EricLew | 0:80ee8f3b695e | 544 | * This requires VDDA equal to or higher than 2.8 V. |
EricLew | 0:80ee8f3b695e | 545 | * @retval None |
EricLew | 0:80ee8f3b695e | 546 | */ |
EricLew | 0:80ee8f3b695e | 547 | void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling) |
EricLew | 0:80ee8f3b695e | 548 | { |
EricLew | 0:80ee8f3b695e | 549 | /* Check the parameters */ |
EricLew | 0:80ee8f3b695e | 550 | assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling)); |
EricLew | 0:80ee8f3b695e | 551 | |
EricLew | 0:80ee8f3b695e | 552 | MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_VRS, VoltageScaling); |
EricLew | 0:80ee8f3b695e | 553 | } |
EricLew | 0:80ee8f3b695e | 554 | |
EricLew | 0:80ee8f3b695e | 555 | /** |
EricLew | 0:80ee8f3b695e | 556 | * @brief Configure the internal voltage reference buffer high impedance mode. |
EricLew | 0:80ee8f3b695e | 557 | * @param Mode: specifies the high impedance mode |
EricLew | 0:80ee8f3b695e | 558 | * This parameter can be one of the following values: |
EricLew | 0:80ee8f3b695e | 559 | * @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE: VREF+ pin is internally connect to VREFINT output. |
EricLew | 0:80ee8f3b695e | 560 | * @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE: VREF+ pin is high impedance. |
EricLew | 0:80ee8f3b695e | 561 | * @retval None |
EricLew | 0:80ee8f3b695e | 562 | */ |
EricLew | 0:80ee8f3b695e | 563 | void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode) |
EricLew | 0:80ee8f3b695e | 564 | { |
EricLew | 0:80ee8f3b695e | 565 | /* Check the parameters */ |
EricLew | 0:80ee8f3b695e | 566 | assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode)); |
EricLew | 0:80ee8f3b695e | 567 | |
EricLew | 0:80ee8f3b695e | 568 | MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode); |
EricLew | 0:80ee8f3b695e | 569 | } |
EricLew | 0:80ee8f3b695e | 570 | |
EricLew | 0:80ee8f3b695e | 571 | /** |
EricLew | 0:80ee8f3b695e | 572 | * @brief Tune the Internal Voltage Reference buffer (VREFBUF). |
EricLew | 0:80ee8f3b695e | 573 | * @retval None |
EricLew | 0:80ee8f3b695e | 574 | */ |
EricLew | 0:80ee8f3b695e | 575 | void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue) |
EricLew | 0:80ee8f3b695e | 576 | { |
EricLew | 0:80ee8f3b695e | 577 | /* Check the parameters */ |
EricLew | 0:80ee8f3b695e | 578 | assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue)); |
EricLew | 0:80ee8f3b695e | 579 | |
EricLew | 0:80ee8f3b695e | 580 | MODIFY_REG(VREFBUF->CCR, VREFBUF_CCR_TRIM, TrimmingValue); |
EricLew | 0:80ee8f3b695e | 581 | } |
EricLew | 0:80ee8f3b695e | 582 | |
EricLew | 0:80ee8f3b695e | 583 | /** |
EricLew | 0:80ee8f3b695e | 584 | * @brief Enable the Internal Voltage Reference buffer (VREFBUF). |
EricLew | 0:80ee8f3b695e | 585 | * @retval HAL_OK/HAL_TIMEOUT |
EricLew | 0:80ee8f3b695e | 586 | */ |
EricLew | 0:80ee8f3b695e | 587 | HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void) |
EricLew | 0:80ee8f3b695e | 588 | { |
EricLew | 0:80ee8f3b695e | 589 | uint32_t tickstart = 0; |
EricLew | 0:80ee8f3b695e | 590 | |
EricLew | 0:80ee8f3b695e | 591 | SET_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR); |
EricLew | 0:80ee8f3b695e | 592 | |
EricLew | 0:80ee8f3b695e | 593 | /* Get Start Tick*/ |
EricLew | 0:80ee8f3b695e | 594 | tickstart = HAL_GetTick(); |
EricLew | 0:80ee8f3b695e | 595 | |
EricLew | 0:80ee8f3b695e | 596 | /* Wait for VRR bit */ |
EricLew | 0:80ee8f3b695e | 597 | while(READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == RESET) |
EricLew | 0:80ee8f3b695e | 598 | { |
EricLew | 0:80ee8f3b695e | 599 | if((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE) |
EricLew | 0:80ee8f3b695e | 600 | { |
EricLew | 0:80ee8f3b695e | 601 | return HAL_TIMEOUT; |
EricLew | 0:80ee8f3b695e | 602 | } |
EricLew | 0:80ee8f3b695e | 603 | } |
EricLew | 0:80ee8f3b695e | 604 | |
EricLew | 0:80ee8f3b695e | 605 | return HAL_OK; |
EricLew | 0:80ee8f3b695e | 606 | } |
EricLew | 0:80ee8f3b695e | 607 | |
EricLew | 0:80ee8f3b695e | 608 | /** |
EricLew | 0:80ee8f3b695e | 609 | * @brief Disable the Internal Voltage Reference buffer (VREFBUF). |
EricLew | 0:80ee8f3b695e | 610 | * |
EricLew | 0:80ee8f3b695e | 611 | * @retval None |
EricLew | 0:80ee8f3b695e | 612 | */ |
EricLew | 0:80ee8f3b695e | 613 | void HAL_SYSCFG_DisableVREFBUF(void) |
EricLew | 0:80ee8f3b695e | 614 | { |
EricLew | 0:80ee8f3b695e | 615 | CLEAR_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR); |
EricLew | 0:80ee8f3b695e | 616 | } |
EricLew | 0:80ee8f3b695e | 617 | |
EricLew | 0:80ee8f3b695e | 618 | /** |
EricLew | 0:80ee8f3b695e | 619 | * @} |
EricLew | 0:80ee8f3b695e | 620 | */ |
EricLew | 0:80ee8f3b695e | 621 | |
EricLew | 0:80ee8f3b695e | 622 | /** |
EricLew | 0:80ee8f3b695e | 623 | * @} |
EricLew | 0:80ee8f3b695e | 624 | */ |
EricLew | 0:80ee8f3b695e | 625 | |
EricLew | 0:80ee8f3b695e | 626 | #endif /* HAL_MODULE_ENABLED */ |
EricLew | 0:80ee8f3b695e | 627 | /** |
EricLew | 0:80ee8f3b695e | 628 | * @} |
EricLew | 0:80ee8f3b695e | 629 | */ |
EricLew | 0:80ee8f3b695e | 630 | |
EricLew | 0:80ee8f3b695e | 631 | /** |
EricLew | 0:80ee8f3b695e | 632 | * @} |
EricLew | 0:80ee8f3b695e | 633 | */ |
EricLew | 0:80ee8f3b695e | 634 | |
EricLew | 0:80ee8f3b695e | 635 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
EricLew | 0:80ee8f3b695e | 636 |