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