STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal.c 00004 * @author MCD Application Team 00005 * @brief HAL module driver. 00006 * This is the common part of the HAL initialization 00007 * 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * Copyright (c) 2017 STMicroelectronics. 00012 * All rights reserved. 00013 * 00014 * This software is licensed under terms that can be found in the LICENSE file 00015 * in the root directory of this software component. 00016 * If no LICENSE file comes with this software, it is provided AS-IS. 00017 * 00018 ****************************************************************************** 00019 @verbatim 00020 ============================================================================== 00021 ##### How to use this driver ##### 00022 ============================================================================== 00023 [..] 00024 The common HAL driver contains a set of generic and common APIs that can be 00025 used by the PPP peripheral drivers and the user to start using the HAL. 00026 [..] 00027 The HAL contains two APIs' categories: 00028 (+) Common HAL APIs 00029 (+) Services HAL APIs 00030 00031 @endverbatim 00032 ****************************************************************************** 00033 */ 00034 00035 /* Includes ------------------------------------------------------------------*/ 00036 #include "stm32l4xx_hal.h" 00037 00038 /** @addtogroup STM32L4xx_HAL_Driver 00039 * @{ 00040 */ 00041 00042 /** @defgroup HAL HAL 00043 * @brief HAL module driver 00044 * @{ 00045 */ 00046 00047 #ifdef HAL_MODULE_ENABLED 00048 00049 /* Private typedef -----------------------------------------------------------*/ 00050 /* Private define ------------------------------------------------------------*/ 00051 /** 00052 * @brief STM32L4xx HAL Driver version number 00053 */ 00054 #define STM32L4XX_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */ 00055 #define STM32L4XX_HAL_VERSION_SUB1 (0x0DU) /*!< [23:16] sub1 version */ 00056 #define STM32L4XX_HAL_VERSION_SUB2 (0x02U) /*!< [15:8] sub2 version */ 00057 #define STM32L4XX_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */ 00058 #define STM32L4XX_HAL_VERSION ((STM32L4XX_HAL_VERSION_MAIN << 24U)\ 00059 |(STM32L4XX_HAL_VERSION_SUB1 << 16U)\ 00060 |(STM32L4XX_HAL_VERSION_SUB2 << 8U)\ 00061 |(STM32L4XX_HAL_VERSION_RC)) 00062 00063 #if defined(VREFBUF) 00064 #define VREFBUF_TIMEOUT_VALUE 10U /* 10 ms (to be confirmed) */ 00065 #endif /* VREFBUF */ 00066 00067 /* ------------ SYSCFG registers bit address in the alias region ------------ */ 00068 #define SYSCFG_OFFSET (SYSCFG_BASE - PERIPH_BASE) 00069 /* --- MEMRMP Register ---*/ 00070 /* Alias word address of FB_MODE bit */ 00071 #define MEMRMP_OFFSET SYSCFG_OFFSET 00072 #define FB_MODE_BitNumber 8U 00073 #define FB_MODE_BB (PERIPH_BB_BASE + (MEMRMP_OFFSET * 32U) + (FB_MODE_BitNumber * 4U)) 00074 00075 /* --- SCSR Register ---*/ 00076 /* Alias word address of SRAM2ER bit */ 00077 #define SCSR_OFFSET (SYSCFG_OFFSET + 0x18U) 00078 #define BRER_BitNumber 0U 00079 #define SCSR_SRAM2ER_BB (PERIPH_BB_BASE + (SCSR_OFFSET * 32U) + (BRER_BitNumber * 4U)) 00080 00081 /* Private macro -------------------------------------------------------------*/ 00082 /* Private variables ---------------------------------------------------------*/ 00083 /* Private function prototypes -----------------------------------------------*/ 00084 00085 /* Exported variables --------------------------------------------------------*/ 00086 00087 /** @defgroup HAL_Exported_Variables HAL Exported Variables 00088 * @{ 00089 */ 00090 __IO uint32_t uwTick; 00091 uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid priority */ 00092 HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */ 00093 /** 00094 * @} 00095 */ 00096 00097 /* Exported functions --------------------------------------------------------*/ 00098 00099 /** @defgroup HAL_Exported_Functions HAL Exported Functions 00100 * @{ 00101 */ 00102 00103 /** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions 00104 * @brief Initialization and de-initialization functions 00105 * 00106 @verbatim 00107 =============================================================================== 00108 ##### Initialization and de-initialization functions ##### 00109 =============================================================================== 00110 [..] This section provides functions allowing to: 00111 (+) Initialize the Flash interface, the NVIC allocation and initial time base 00112 clock configuration. 00113 (+) De-initialize common part of the HAL. 00114 (+) Configure the time base source to have 1ms time base with a dedicated 00115 Tick interrupt priority. 00116 (++) SysTick timer is used by default as source of time base, but user 00117 can eventually implement his proper time base source (a general purpose 00118 timer for example or other time source), keeping in mind that Time base 00119 duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 00120 handled in milliseconds basis. 00121 (++) Time base configuration function (HAL_InitTick ()) is called automatically 00122 at the beginning of the program after reset by HAL_Init() or at any time 00123 when clock is configured, by HAL_RCC_ClockConfig(). 00124 (++) Source of time base is configured to generate interrupts at regular 00125 time intervals. Care must be taken if HAL_Delay() is called from a 00126 peripheral ISR process, the Tick interrupt line must have higher priority 00127 (numerically lower) than the peripheral interrupt. Otherwise the caller 00128 ISR process will be blocked. 00129 (++) functions affecting time base configurations are declared as __weak 00130 to make override possible in case of other implementations in user file. 00131 @endverbatim 00132 * @{ 00133 */ 00134 00135 /** 00136 * @brief Configure the Flash prefetch, the Instruction and Data caches, 00137 * the time base source, NVIC and any required global low level hardware 00138 * by calling the HAL_MspInit() callback function to be optionally defined in user file 00139 * stm32l4xx_hal_msp.c. 00140 * 00141 * @note HAL_Init() function is called at the beginning of program after reset and before 00142 * the clock configuration. 00143 * 00144 * @note In the default implementation the System Timer (Systick) is used as source of time base. 00145 * The Systick configuration is based on MSI clock, as MSI is the clock 00146 * used after a system Reset and the NVIC configuration is set to Priority group 4. 00147 * Once done, time base tick starts incrementing: the tick variable counter is incremented 00148 * each 1ms in the SysTick_Handler() interrupt handler. 00149 * 00150 * @retval HAL status 00151 */ 00152 HAL_StatusTypeDef HAL_Init(void) 00153 { 00154 HAL_StatusTypeDef status = HAL_OK; 00155 00156 /* Configure Flash prefetch, Instruction cache, Data cache */ 00157 /* Default configuration at reset is: */ 00158 /* - Prefetch disabled */ 00159 /* - Instruction cache enabled */ 00160 /* - Data cache enabled */ 00161 #if (INSTRUCTION_CACHE_ENABLE == 0) 00162 __HAL_FLASH_INSTRUCTION_CACHE_DISABLE(); 00163 #endif /* INSTRUCTION_CACHE_ENABLE */ 00164 00165 #if (DATA_CACHE_ENABLE == 0) 00166 __HAL_FLASH_DATA_CACHE_DISABLE(); 00167 #endif /* DATA_CACHE_ENABLE */ 00168 00169 #if (PREFETCH_ENABLE != 0) 00170 __HAL_FLASH_PREFETCH_BUFFER_ENABLE(); 00171 #endif /* PREFETCH_ENABLE */ 00172 00173 /* Set Interrupt Group Priority */ 00174 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4); 00175 00176 /* Use SysTick as time base source and configure 1ms tick (default clock after Reset is MSI) */ 00177 if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) 00178 { 00179 status = HAL_ERROR; 00180 } 00181 else 00182 { 00183 /* Init the low level hardware */ 00184 HAL_MspInit(); 00185 } 00186 00187 /* Return function status */ 00188 return status; 00189 } 00190 00191 /** 00192 * @brief De-initialize common part of the HAL and stop the source of time base. 00193 * @note This function is optional. 00194 * @retval HAL status 00195 */ 00196 HAL_StatusTypeDef HAL_DeInit(void) 00197 { 00198 /* Reset of all peripherals */ 00199 __HAL_RCC_APB1_FORCE_RESET(); 00200 __HAL_RCC_APB1_RELEASE_RESET(); 00201 00202 __HAL_RCC_APB2_FORCE_RESET(); 00203 __HAL_RCC_APB2_RELEASE_RESET(); 00204 00205 __HAL_RCC_AHB1_FORCE_RESET(); 00206 __HAL_RCC_AHB1_RELEASE_RESET(); 00207 00208 __HAL_RCC_AHB2_FORCE_RESET(); 00209 __HAL_RCC_AHB2_RELEASE_RESET(); 00210 00211 __HAL_RCC_AHB3_FORCE_RESET(); 00212 __HAL_RCC_AHB3_RELEASE_RESET(); 00213 00214 /* De-Init the low level hardware */ 00215 HAL_MspDeInit(); 00216 00217 /* Return function status */ 00218 return HAL_OK; 00219 } 00220 00221 /** 00222 * @brief Initialize the MSP. 00223 * @retval None 00224 */ 00225 __weak void HAL_MspInit(void) 00226 { 00227 /* NOTE : This function should not be modified, when the callback is needed, 00228 the HAL_MspInit could be implemented in the user file 00229 */ 00230 } 00231 00232 /** 00233 * @brief DeInitialize the MSP. 00234 * @retval None 00235 */ 00236 __weak void HAL_MspDeInit(void) 00237 { 00238 /* NOTE : This function should not be modified, when the callback is needed, 00239 the HAL_MspDeInit could be implemented in the user file 00240 */ 00241 } 00242 00243 /** 00244 * @brief This function configures the source of the time base: 00245 * The time source is configured to have 1ms time base with a dedicated 00246 * Tick interrupt priority. 00247 * @note This function is called automatically at the beginning of program after 00248 * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig(). 00249 * @note In the default implementation, SysTick timer is the source of time base. 00250 * It is used to generate interrupts at regular time intervals. 00251 * Care must be taken if HAL_Delay() is called from a peripheral ISR process, 00252 * The SysTick interrupt must have higher priority (numerically lower) 00253 * than the peripheral interrupt. Otherwise the caller ISR process will be blocked. 00254 * The function is declared as __weak to be overwritten in case of other 00255 * implementation in user file. 00256 * @param TickPriority Tick interrupt priority. 00257 * @retval HAL status 00258 */ 00259 __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority) 00260 { 00261 HAL_StatusTypeDef status = HAL_OK; 00262 00263 /* Check uwTickFreq for MisraC 2012 (even if uwTickFreq is a enum type that doesn't take the value zero)*/ 00264 if ((uint32_t)uwTickFreq != 0U) 00265 { 00266 /*Configure the SysTick to have interrupt in 1ms time basis*/ 00267 if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / (uint32_t)uwTickFreq)) == 0U) 00268 { 00269 /* Configure the SysTick IRQ priority */ 00270 if (TickPriority < (1UL << __NVIC_PRIO_BITS)) 00271 { 00272 HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U); 00273 uwTickPrio = TickPriority; 00274 } 00275 else 00276 { 00277 status = HAL_ERROR; 00278 } 00279 } 00280 else 00281 { 00282 status = HAL_ERROR; 00283 } 00284 } 00285 else 00286 { 00287 status = HAL_ERROR; 00288 } 00289 00290 /* Return function status */ 00291 return status; 00292 } 00293 00294 /** 00295 * @} 00296 */ 00297 00298 /** @defgroup HAL_Exported_Functions_Group2 HAL Control functions 00299 * @brief HAL Control functions 00300 * 00301 @verbatim 00302 =============================================================================== 00303 ##### HAL Control functions ##### 00304 =============================================================================== 00305 [..] This section provides functions allowing to: 00306 (+) Provide a tick value in millisecond 00307 (+) Provide a blocking delay in millisecond 00308 (+) Suspend the time base source interrupt 00309 (+) Resume the time base source interrupt 00310 (+) Get the HAL API driver version 00311 (+) Get the device identifier 00312 (+) Get the device revision identifier 00313 00314 @endverbatim 00315 * @{ 00316 */ 00317 00318 /** 00319 * @brief This function is called to increment a global variable "uwTick" 00320 * used as application time base. 00321 * @note In the default implementation, this variable is incremented each 1ms 00322 * in SysTick ISR. 00323 * @note This function is declared as __weak to be overwritten in case of other 00324 * implementations in user file. 00325 * @retval None 00326 */ 00327 __weak void HAL_IncTick(void) 00328 { 00329 uwTick += (uint32_t)uwTickFreq; 00330 } 00331 00332 /** 00333 * @brief Provide a tick value in millisecond. 00334 * @note This function is declared as __weak to be overwritten in case of other 00335 * implementations in user file. 00336 * @retval tick value 00337 */ 00338 __weak uint32_t HAL_GetTick(void) 00339 { 00340 return uwTick; 00341 } 00342 00343 /** 00344 * @brief This function returns a tick priority. 00345 * @retval tick priority 00346 */ 00347 uint32_t HAL_GetTickPrio(void) 00348 { 00349 return uwTickPrio; 00350 } 00351 00352 /** 00353 * @brief Set new tick Freq. 00354 * @param Freq tick frequency 00355 * @retval HAL status 00356 */ 00357 HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq) 00358 { 00359 HAL_StatusTypeDef status = HAL_OK; 00360 HAL_TickFreqTypeDef prevTickFreq; 00361 00362 if (uwTickFreq != Freq) 00363 { 00364 /* Back up uwTickFreq frequency */ 00365 prevTickFreq = uwTickFreq; 00366 00367 /* Update uwTickFreq global variable used by HAL_InitTick() */ 00368 uwTickFreq = Freq; 00369 00370 /* Apply the new tick Freq */ 00371 status = HAL_InitTick(uwTickPrio); 00372 if (status != HAL_OK) 00373 { 00374 /* Restore previous tick frequency */ 00375 uwTickFreq = prevTickFreq; 00376 } 00377 } 00378 00379 return status; 00380 } 00381 00382 /** 00383 * @brief Return tick frequency. 00384 * @retval tick period in Hz 00385 */ 00386 HAL_TickFreqTypeDef HAL_GetTickFreq(void) 00387 { 00388 return uwTickFreq; 00389 } 00390 00391 /** 00392 * @brief This function provides minimum delay (in milliseconds) based 00393 * on variable incremented. 00394 * @note In the default implementation , SysTick timer is the source of time base. 00395 * It is used to generate interrupts at regular time intervals where uwTick 00396 * is incremented. 00397 * @note This function is declared as __weak to be overwritten in case of other 00398 * implementations in user file. 00399 * @param Delay specifies the delay time length, in milliseconds. 00400 * @retval None 00401 */ 00402 __weak void HAL_Delay(uint32_t Delay) 00403 { 00404 uint32_t tickstart = HAL_GetTick(); 00405 uint32_t wait = Delay; 00406 00407 /* Add a period to guaranty minimum wait */ 00408 if (wait < HAL_MAX_DELAY) 00409 { 00410 wait += (uint32_t)uwTickFreq; 00411 } 00412 00413 while ((HAL_GetTick() - tickstart) < wait) 00414 { 00415 } 00416 } 00417 00418 /** 00419 * @brief Suspend Tick increment. 00420 * @note In the default implementation , SysTick timer is the source of time base. It is 00421 * used to generate interrupts at regular time intervals. Once HAL_SuspendTick() 00422 * is called, the SysTick interrupt will be disabled and so Tick increment 00423 * is suspended. 00424 * @note This function is declared as __weak to be overwritten in case of other 00425 * implementations in user file. 00426 * @retval None 00427 */ 00428 __weak void HAL_SuspendTick(void) 00429 { 00430 /* Disable SysTick Interrupt */ 00431 SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk; 00432 } 00433 00434 /** 00435 * @brief Resume Tick increment. 00436 * @note In the default implementation , SysTick timer is the source of time base. It is 00437 * used to generate interrupts at regular time intervals. Once HAL_ResumeTick() 00438 * is called, the SysTick interrupt will be enabled and so Tick increment 00439 * is resumed. 00440 * @note This function is declared as __weak to be overwritten in case of other 00441 * implementations in user file. 00442 * @retval None 00443 */ 00444 __weak void HAL_ResumeTick(void) 00445 { 00446 /* Enable SysTick Interrupt */ 00447 SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; 00448 } 00449 00450 /** 00451 * @brief Return the HAL revision. 00452 * @retval version : 0xXYZR (8bits for each decimal, R for RC) 00453 */ 00454 uint32_t HAL_GetHalVersion(void) 00455 { 00456 return STM32L4XX_HAL_VERSION; 00457 } 00458 00459 /** 00460 * @brief Return the device revision identifier. 00461 * @retval Device revision identifier 00462 */ 00463 uint32_t HAL_GetREVID(void) 00464 { 00465 return((DBGMCU->IDCODE & DBGMCU_IDCODE_REV_ID) >> 16); 00466 } 00467 00468 /** 00469 * @brief Return the device identifier. 00470 * @retval Device identifier 00471 */ 00472 uint32_t HAL_GetDEVID(void) 00473 { 00474 return(DBGMCU->IDCODE & DBGMCU_IDCODE_DEV_ID); 00475 } 00476 00477 /** 00478 * @brief Return the first word of the unique device identifier (UID based on 96 bits) 00479 * @retval Device identifier 00480 */ 00481 uint32_t HAL_GetUIDw0(void) 00482 { 00483 return(READ_REG(*((uint32_t *)UID_BASE))); 00484 } 00485 00486 /** 00487 * @brief Return the second word of the unique device identifier (UID based on 96 bits) 00488 * @retval Device identifier 00489 */ 00490 uint32_t HAL_GetUIDw1(void) 00491 { 00492 return(READ_REG(*((uint32_t *)(UID_BASE + 4U)))); 00493 } 00494 00495 /** 00496 * @brief Return the third word of the unique device identifier (UID based on 96 bits) 00497 * @retval Device identifier 00498 */ 00499 uint32_t HAL_GetUIDw2(void) 00500 { 00501 return(READ_REG(*((uint32_t *)(UID_BASE + 8U)))); 00502 } 00503 00504 /** 00505 * @} 00506 */ 00507 00508 /** @defgroup HAL_Exported_Functions_Group3 HAL Debug functions 00509 * @brief HAL Debug functions 00510 * 00511 @verbatim 00512 =============================================================================== 00513 ##### HAL Debug functions ##### 00514 =============================================================================== 00515 [..] This section provides functions allowing to: 00516 (+) Enable/Disable Debug module during SLEEP mode 00517 (+) Enable/Disable Debug module during STOP0/STOP1/STOP2 modes 00518 (+) Enable/Disable Debug module during STANDBY mode 00519 00520 @endverbatim 00521 * @{ 00522 */ 00523 00524 /** 00525 * @brief Enable the Debug Module during SLEEP mode. 00526 * @retval None 00527 */ 00528 void HAL_DBGMCU_EnableDBGSleepMode(void) 00529 { 00530 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); 00531 } 00532 00533 /** 00534 * @brief Disable the Debug Module during SLEEP mode. 00535 * @retval None 00536 */ 00537 void HAL_DBGMCU_DisableDBGSleepMode(void) 00538 { 00539 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP); 00540 } 00541 00542 /** 00543 * @brief Enable the Debug Module during STOP0/STOP1/STOP2 modes. 00544 * @retval None 00545 */ 00546 void HAL_DBGMCU_EnableDBGStopMode(void) 00547 { 00548 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); 00549 } 00550 00551 /** 00552 * @brief Disable the Debug Module during STOP0/STOP1/STOP2 modes. 00553 * @retval None 00554 */ 00555 void HAL_DBGMCU_DisableDBGStopMode(void) 00556 { 00557 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP); 00558 } 00559 00560 /** 00561 * @brief Enable the Debug Module during STANDBY mode. 00562 * @retval None 00563 */ 00564 void HAL_DBGMCU_EnableDBGStandbyMode(void) 00565 { 00566 SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); 00567 } 00568 00569 /** 00570 * @brief Disable the Debug Module during STANDBY mode. 00571 * @retval None 00572 */ 00573 void HAL_DBGMCU_DisableDBGStandbyMode(void) 00574 { 00575 CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY); 00576 } 00577 00578 /** 00579 * @} 00580 */ 00581 00582 /** @defgroup HAL_Exported_Functions_Group4 HAL SYSCFG configuration functions 00583 * @brief HAL SYSCFG configuration functions 00584 * 00585 @verbatim 00586 =============================================================================== 00587 ##### HAL SYSCFG configuration functions ##### 00588 =============================================================================== 00589 [..] This section provides functions allowing to: 00590 (+) Start a hardware SRAM2 erase operation 00591 (+) Enable/Disable the Internal FLASH Bank Swapping 00592 (+) Configure the Voltage reference buffer 00593 (+) Enable/Disable the Voltage reference buffer 00594 (+) Enable/Disable the I/O analog switch voltage booster 00595 00596 @endverbatim 00597 * @{ 00598 */ 00599 00600 /** 00601 * @brief Start a hardware SRAM2 erase operation. 00602 * @note As long as SRAM2 is not erased the SRAM2ER bit will be set. 00603 * This bit is automatically reset at the end of the SRAM2 erase operation. 00604 * @retval None 00605 */ 00606 void HAL_SYSCFG_SRAM2Erase(void) 00607 { 00608 /* unlock the write protection of the SRAM2ER bit */ 00609 SYSCFG->SKR = 0xCA; 00610 SYSCFG->SKR = 0x53; 00611 /* Starts a hardware SRAM2 erase operation*/ 00612 *(__IO uint32_t *) SCSR_SRAM2ER_BB = 0x00000001UL; 00613 } 00614 00615 /** 00616 * @brief Enable the Internal FLASH Bank Swapping. 00617 * 00618 * @note This function can be used only for STM32L4xx devices. 00619 * 00620 * @note Flash Bank2 mapped at 0x08000000 (and aliased @0x00000000) 00621 * and Flash Bank1 mapped at 0x08100000 (and aliased at 0x00100000) 00622 * 00623 * @retval None 00624 */ 00625 void HAL_SYSCFG_EnableMemorySwappingBank(void) 00626 { 00627 *(__IO uint32_t *)FB_MODE_BB = 0x00000001UL; 00628 } 00629 00630 /** 00631 * @brief Disable the Internal FLASH Bank Swapping. 00632 * 00633 * @note This function can be used only for STM32L4xx devices. 00634 * 00635 * @note The default state : Flash Bank1 mapped at 0x08000000 (and aliased @0x0000 0000) 00636 * and Flash Bank2 mapped at 0x08100000 (and aliased at 0x00100000) 00637 * 00638 * @retval None 00639 */ 00640 void HAL_SYSCFG_DisableMemorySwappingBank(void) 00641 { 00642 00643 *(__IO uint32_t *)FB_MODE_BB = 0x00000000UL; 00644 } 00645 00646 #if defined(VREFBUF) 00647 /** 00648 * @brief Configure the internal voltage reference buffer voltage scale. 00649 * @param VoltageScaling specifies the output voltage to achieve 00650 * This parameter can be one of the following values: 00651 * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE0: VREF_OUT1 around 2.048 V. 00652 * This requires VDDA equal to or higher than 2.4 V. 00653 * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE1: VREF_OUT2 around 2.5 V. 00654 * This requires VDDA equal to or higher than 2.8 V. 00655 * @retval None 00656 */ 00657 void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling) 00658 { 00659 /* Check the parameters */ 00660 assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling)); 00661 00662 MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_VRS, VoltageScaling); 00663 } 00664 00665 /** 00666 * @brief Configure the internal voltage reference buffer high impedance mode. 00667 * @param Mode specifies the high impedance mode 00668 * This parameter can be one of the following values: 00669 * @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE: VREF+ pin is internally connect to VREFINT output. 00670 * @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE: VREF+ pin is high impedance. 00671 * @retval None 00672 */ 00673 void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode) 00674 { 00675 /* Check the parameters */ 00676 assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode)); 00677 00678 MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode); 00679 } 00680 00681 /** 00682 * @brief Tune the Internal Voltage Reference buffer (VREFBUF). 00683 * @retval None 00684 */ 00685 void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue) 00686 { 00687 /* Check the parameters */ 00688 assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue)); 00689 00690 MODIFY_REG(VREFBUF->CCR, VREFBUF_CCR_TRIM, TrimmingValue); 00691 } 00692 00693 /** 00694 * @brief Enable the Internal Voltage Reference buffer (VREFBUF). 00695 * @retval HAL_OK/HAL_TIMEOUT 00696 */ 00697 HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void) 00698 { 00699 uint32_t tickstart; 00700 00701 SET_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR); 00702 00703 /* Get Start Tick*/ 00704 tickstart = HAL_GetTick(); 00705 00706 /* Wait for VRR bit */ 00707 while(READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == 0U) 00708 { 00709 if((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE) 00710 { 00711 return HAL_TIMEOUT; 00712 } 00713 } 00714 00715 return HAL_OK; 00716 } 00717 00718 /** 00719 * @brief Disable the Internal Voltage Reference buffer (VREFBUF). 00720 * 00721 * @retval None 00722 */ 00723 void HAL_SYSCFG_DisableVREFBUF(void) 00724 { 00725 CLEAR_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR); 00726 } 00727 #endif /* VREFBUF */ 00728 00729 /** 00730 * @brief Enable the I/O analog switch voltage booster 00731 * 00732 * @retval None 00733 */ 00734 void HAL_SYSCFG_EnableIOAnalogSwitchBooster(void) 00735 { 00736 SET_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_BOOSTEN); 00737 } 00738 00739 /** 00740 * @brief Disable the I/O analog switch voltage booster 00741 * 00742 * @retval None 00743 */ 00744 void HAL_SYSCFG_DisableIOAnalogSwitchBooster(void) 00745 { 00746 CLEAR_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_BOOSTEN); 00747 } 00748 00749 /** 00750 * @} 00751 */ 00752 00753 /** 00754 * @} 00755 */ 00756 00757 #endif /* HAL_MODULE_ENABLED */ 00758 /** 00759 * @} 00760 */ 00761 00762 /** 00763 * @} 00764 */