xref: /btstack/port/stm32-l451-miromico-sx1280/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c (revision 2fd737d36a1de5d778cacc671d4b4d8c4f3fed82)
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>&copy; Copyright (c) 2017 STMicroelectronics.
25   * All rights reserved.</center></h2>
26   *
27   * This software component is licensed by ST under BSD 3-Clause license,
28   * the "License"; You may not use this file except in compliance with the
29   * License. You may obtain a copy of the License at:
30   *                        opensource.org/licenses/BSD-3-Clause
31   *
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   (0x0BU) /*!< [23:16] sub1 version */
56 #define STM32L4XX_HAL_VERSION_SUB2   (0x01U) /*!< [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 uint32_t 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   if (uwTickFreq != 0U)
264   {
265     /*Configure the SysTick to have interrupt in 1ms time basis*/
266     if (HAL_SYSTICK_Config(SystemCoreClock / (1000U / uwTickFreq)) == 0U)
267     {
268       /* Configure the SysTick IRQ priority */
269       if (TickPriority < (1UL << __NVIC_PRIO_BITS))
270       {
271         HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
272         uwTickPrio = TickPriority;
273       }
274       else
275       {
276         status = HAL_ERROR;
277       }
278     }
279     else
280     {
281       status = HAL_ERROR;
282     }
283   }
284   else
285   {
286     status = HAL_ERROR;
287   }
288 
289   /* Return function status */
290   return status;
291 }
292 
293 /**
294   * @}
295   */
296 
297 /** @defgroup HAL_Exported_Functions_Group2 HAL Control functions
298  *  @brief    HAL Control functions
299  *
300 @verbatim
301  ===============================================================================
302                       ##### HAL Control functions #####
303  ===============================================================================
304     [..]  This section provides functions allowing to:
305       (+) Provide a tick value in millisecond
306       (+) Provide a blocking delay in millisecond
307       (+) Suspend the time base source interrupt
308       (+) Resume the time base source interrupt
309       (+) Get the HAL API driver version
310       (+) Get the device identifier
311       (+) Get the device revision identifier
312 
313 @endverbatim
314   * @{
315   */
316 
317 /**
318   * @brief This function is called to increment a global variable "uwTick"
319   *        used as application time base.
320   * @note In the default implementation, this variable is incremented each 1ms
321   *       in SysTick ISR.
322  * @note This function is declared as __weak to be overwritten in case of other
323   *      implementations in user file.
324   * @retval None
325   */
HAL_IncTick(void)326 __weak void HAL_IncTick(void)
327 {
328   uwTick += uwTickFreq;
329 }
330 
331 /**
332   * @brief Provide a tick value in millisecond.
333   * @note This function is declared as __weak to be overwritten in case of other
334   *       implementations in user file.
335   * @retval tick value
336   */
HAL_GetTick(void)337 __weak uint32_t HAL_GetTick(void)
338 {
339   return uwTick;
340 }
341 
342 /**
343   * @brief This function returns a tick priority.
344   * @retval tick priority
345   */
HAL_GetTickPrio(void)346 uint32_t HAL_GetTickPrio(void)
347 {
348   return uwTickPrio;
349 }
350 
351 /**
352   * @brief Set new tick Freq.
353   * @param Freq tick frequency
354   * @retval HAL status
355   */
HAL_SetTickFreq(uint32_t Freq)356 HAL_StatusTypeDef HAL_SetTickFreq(uint32_t Freq)
357 {
358   HAL_StatusTypeDef status  = HAL_OK;
359   assert_param(IS_TICKFREQ(Freq));
360 
361   if (uwTickFreq != Freq)
362   {
363     /* Apply the new tick Freq  */
364     status = HAL_InitTick(uwTickPrio);
365     if (status == HAL_OK)
366     {
367       uwTickFreq = Freq;
368     }
369   }
370 
371   return status;
372 }
373 
374 /**
375   * @brief Return tick frequency.
376   * @retval tick period in Hz
377   */
HAL_GetTickFreq(void)378 uint32_t HAL_GetTickFreq(void)
379 {
380   return uwTickFreq;
381 }
382 
383 /**
384   * @brief This function provides minimum delay (in milliseconds) based
385   *        on variable incremented.
386   * @note In the default implementation , SysTick timer is the source of time base.
387   *       It is used to generate interrupts at regular time intervals where uwTick
388   *       is incremented.
389   * @note This function is declared as __weak to be overwritten in case of other
390   *       implementations in user file.
391   * @param Delay  specifies the delay time length, in milliseconds.
392   * @retval None
393   */
HAL_Delay(uint32_t Delay)394 __weak void HAL_Delay(uint32_t Delay)
395 {
396   uint32_t tickstart = HAL_GetTick();
397   uint32_t wait = Delay;
398 
399   /* Add a period to guaranty minimum wait */
400   if (wait < HAL_MAX_DELAY)
401   {
402     wait += (uint32_t)(uwTickFreq);
403   }
404 
405   while((HAL_GetTick() - tickstart) < wait)
406   {
407   }
408 }
409 
410 /**
411   * @brief Suspend Tick increment.
412   * @note In the default implementation , SysTick timer is the source of time base. It is
413   *       used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
414   *       is called, the SysTick interrupt will be disabled and so Tick increment
415   *       is suspended.
416   * @note This function is declared as __weak to be overwritten in case of other
417   *       implementations in user file.
418   * @retval None
419   */
HAL_SuspendTick(void)420 __weak void HAL_SuspendTick(void)
421 {
422   /* Disable SysTick Interrupt */
423   SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
424 }
425 
426 /**
427   * @brief Resume Tick increment.
428   * @note In the default implementation , SysTick timer is the source of time base. It is
429   *       used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
430   *       is called, the SysTick interrupt will be enabled and so Tick increment
431   *       is resumed.
432   * @note This function is declared as __weak to be overwritten in case of other
433   *       implementations in user file.
434   * @retval None
435   */
HAL_ResumeTick(void)436 __weak void HAL_ResumeTick(void)
437 {
438   /* Enable SysTick Interrupt */
439   SysTick->CTRL  |= SysTick_CTRL_TICKINT_Msk;
440 }
441 
442 /**
443   * @brief  Return the HAL revision.
444   * @retval version : 0xXYZR (8bits for each decimal, R for RC)
445   */
HAL_GetHalVersion(void)446 uint32_t HAL_GetHalVersion(void)
447 {
448   return STM32L4XX_HAL_VERSION;
449 }
450 
451 /**
452   * @brief  Return the device revision identifier.
453   * @retval Device revision identifier
454   */
HAL_GetREVID(void)455 uint32_t HAL_GetREVID(void)
456 {
457   return((DBGMCU->IDCODE & DBGMCU_IDCODE_REV_ID) >> 16);
458 }
459 
460 /**
461   * @brief  Return the device identifier.
462   * @retval Device identifier
463   */
HAL_GetDEVID(void)464 uint32_t HAL_GetDEVID(void)
465 {
466   return(DBGMCU->IDCODE & DBGMCU_IDCODE_DEV_ID);
467 }
468 
469 /**
470   * @brief  Return the first word of the unique device identifier (UID based on 96 bits)
471   * @retval Device identifier
472   */
HAL_GetUIDw0(void)473 uint32_t HAL_GetUIDw0(void)
474 {
475   return(READ_REG(*((uint32_t *)UID_BASE)));
476 }
477 
478 /**
479   * @brief  Return the second word of the unique device identifier (UID based on 96 bits)
480   * @retval Device identifier
481   */
HAL_GetUIDw1(void)482 uint32_t HAL_GetUIDw1(void)
483 {
484   return(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
485 }
486 
487 /**
488   * @brief  Return the third word of the unique device identifier (UID based on 96 bits)
489   * @retval Device identifier
490   */
HAL_GetUIDw2(void)491 uint32_t HAL_GetUIDw2(void)
492 {
493   return(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
494 }
495 
496 /**
497   * @}
498   */
499 
500 /** @defgroup HAL_Exported_Functions_Group3 HAL Debug functions
501  *  @brief    HAL Debug functions
502  *
503 @verbatim
504  ===============================================================================
505                       ##### HAL Debug functions #####
506  ===============================================================================
507     [..]  This section provides functions allowing to:
508       (+) Enable/Disable Debug module during SLEEP mode
509       (+) Enable/Disable Debug module during STOP0/STOP1/STOP2 modes
510       (+) Enable/Disable Debug module during STANDBY mode
511 
512 @endverbatim
513   * @{
514   */
515 
516 /**
517   * @brief  Enable the Debug Module during SLEEP mode.
518   * @retval None
519   */
HAL_DBGMCU_EnableDBGSleepMode(void)520 void HAL_DBGMCU_EnableDBGSleepMode(void)
521 {
522   SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
523 }
524 
525 /**
526   * @brief  Disable the Debug Module during SLEEP mode.
527   * @retval None
528   */
HAL_DBGMCU_DisableDBGSleepMode(void)529 void HAL_DBGMCU_DisableDBGSleepMode(void)
530 {
531   CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
532 }
533 
534 /**
535   * @brief  Enable the Debug Module during STOP0/STOP1/STOP2 modes.
536   * @retval None
537   */
HAL_DBGMCU_EnableDBGStopMode(void)538 void HAL_DBGMCU_EnableDBGStopMode(void)
539 {
540   SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
541 }
542 
543 /**
544   * @brief  Disable the Debug Module during STOP0/STOP1/STOP2 modes.
545   * @retval None
546   */
HAL_DBGMCU_DisableDBGStopMode(void)547 void HAL_DBGMCU_DisableDBGStopMode(void)
548 {
549   CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
550 }
551 
552 /**
553   * @brief  Enable the Debug Module during STANDBY mode.
554   * @retval None
555   */
HAL_DBGMCU_EnableDBGStandbyMode(void)556 void HAL_DBGMCU_EnableDBGStandbyMode(void)
557 {
558   SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
559 }
560 
561 /**
562   * @brief  Disable the Debug Module during STANDBY mode.
563   * @retval None
564   */
HAL_DBGMCU_DisableDBGStandbyMode(void)565 void HAL_DBGMCU_DisableDBGStandbyMode(void)
566 {
567   CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
568 }
569 
570 /**
571   * @}
572   */
573 
574 /** @defgroup HAL_Exported_Functions_Group4 HAL SYSCFG configuration functions
575  *  @brief    HAL SYSCFG configuration functions
576  *
577 @verbatim
578  ===============================================================================
579                       ##### HAL SYSCFG configuration functions #####
580  ===============================================================================
581     [..]  This section provides functions allowing to:
582       (+) Start a hardware SRAM2 erase operation
583       (+) Enable/Disable the Internal FLASH Bank Swapping
584       (+) Configure the Voltage reference buffer
585       (+) Enable/Disable the Voltage reference buffer
586       (+) Enable/Disable the I/O analog switch voltage booster
587 
588 @endverbatim
589   * @{
590   */
591 
592 /**
593   * @brief  Start a hardware SRAM2 erase operation.
594   * @note   As long as SRAM2 is not erased the SRAM2ER bit will be set.
595   *         This bit is automatically reset at the end of the SRAM2 erase operation.
596   * @retval None
597   */
HAL_SYSCFG_SRAM2Erase(void)598 void HAL_SYSCFG_SRAM2Erase(void)
599 {
600   /* unlock the write protection of the SRAM2ER bit */
601   SYSCFG->SKR = 0xCA;
602   SYSCFG->SKR = 0x53;
603   /* Starts a hardware SRAM2 erase operation*/
604   *(__IO uint32_t *) SCSR_SRAM2ER_BB = 0x00000001UL;
605 }
606 
607 /**
608   * @brief  Enable the Internal FLASH Bank Swapping.
609   *
610   * @note   This function can be used only for STM32L4xx devices.
611   *
612   * @note   Flash Bank2 mapped at 0x08000000 (and aliased @0x00000000)
613   *         and Flash Bank1 mapped at 0x08100000 (and aliased at 0x00100000)
614   *
615   * @retval None
616   */
HAL_SYSCFG_EnableMemorySwappingBank(void)617 void HAL_SYSCFG_EnableMemorySwappingBank(void)
618 {
619   *(__IO uint32_t *)FB_MODE_BB = 0x00000001UL;
620 }
621 
622 /**
623   * @brief  Disable the Internal FLASH Bank Swapping.
624   *
625   * @note   This function can be used only for STM32L4xx devices.
626   *
627   * @note   The default state : Flash Bank1 mapped at 0x08000000 (and aliased @0x0000 0000)
628   *         and Flash Bank2 mapped at 0x08100000 (and aliased at 0x00100000)
629   *
630   * @retval None
631   */
HAL_SYSCFG_DisableMemorySwappingBank(void)632 void HAL_SYSCFG_DisableMemorySwappingBank(void)
633 {
634 
635   *(__IO uint32_t *)FB_MODE_BB = 0x00000000UL;
636 }
637 
638 #if defined(VREFBUF)
639 /**
640   * @brief Configure the internal voltage reference buffer voltage scale.
641   * @param VoltageScaling  specifies the output voltage to achieve
642   *          This parameter can be one of the following values:
643   *            @arg SYSCFG_VREFBUF_VOLTAGE_SCALE0: VREF_OUT1 around 2.048 V.
644   *                                                This requires VDDA equal to or higher than 2.4 V.
645   *            @arg SYSCFG_VREFBUF_VOLTAGE_SCALE1: VREF_OUT2 around 2.5 V.
646   *                                                This requires VDDA equal to or higher than 2.8 V.
647   * @retval None
648   */
HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)649 void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)
650 {
651   /* Check the parameters */
652   assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling));
653 
654   MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_VRS, VoltageScaling);
655 }
656 
657 /**
658   * @brief Configure the internal voltage reference buffer high impedance mode.
659   * @param Mode  specifies the high impedance mode
660   *          This parameter can be one of the following values:
661   *            @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE: VREF+ pin is internally connect to VREFINT output.
662   *            @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE: VREF+ pin is high impedance.
663   * @retval None
664   */
HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)665 void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)
666 {
667   /* Check the parameters */
668   assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode));
669 
670   MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode);
671 }
672 
673 /**
674   * @brief  Tune the Internal Voltage Reference buffer (VREFBUF).
675   * @retval None
676   */
HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)677 void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)
678 {
679   /* Check the parameters */
680   assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
681 
682   MODIFY_REG(VREFBUF->CCR, VREFBUF_CCR_TRIM, TrimmingValue);
683 }
684 
685 /**
686   * @brief  Enable the Internal Voltage Reference buffer (VREFBUF).
687   * @retval HAL_OK/HAL_TIMEOUT
688   */
HAL_SYSCFG_EnableVREFBUF(void)689 HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void)
690 {
691   uint32_t  tickstart;
692 
693   SET_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
694 
695   /* Get Start Tick*/
696   tickstart = HAL_GetTick();
697 
698   /* Wait for VRR bit  */
699   while(READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == 0U)
700   {
701     if((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE)
702     {
703       return HAL_TIMEOUT;
704     }
705   }
706 
707   return HAL_OK;
708 }
709 
710 /**
711   * @brief  Disable the Internal Voltage Reference buffer (VREFBUF).
712   *
713   * @retval None
714   */
HAL_SYSCFG_DisableVREFBUF(void)715 void HAL_SYSCFG_DisableVREFBUF(void)
716 {
717   CLEAR_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
718 }
719 #endif /* VREFBUF */
720 
721 /**
722   * @brief  Enable the I/O analog switch voltage booster
723   *
724   * @retval None
725   */
HAL_SYSCFG_EnableIOAnalogSwitchBooster(void)726 void HAL_SYSCFG_EnableIOAnalogSwitchBooster(void)
727 {
728   SET_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_BOOSTEN);
729 }
730 
731 /**
732   * @brief  Disable the I/O analog switch voltage booster
733   *
734   * @retval None
735   */
HAL_SYSCFG_DisableIOAnalogSwitchBooster(void)736 void HAL_SYSCFG_DisableIOAnalogSwitchBooster(void)
737 {
738   CLEAR_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_BOOSTEN);
739 }
740 
741 /**
742   * @}
743   */
744 
745 /**
746   * @}
747   */
748 
749 #endif /* HAL_MODULE_ENABLED */
750 /**
751   * @}
752   */
753 
754 /**
755   * @}
756   */
757 
758 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
759