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