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