1 /**
2   ******************************************************************************
3   * @file    stm32wbxx_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 "stm32wbxx_hal.h"
36 
37 /** @addtogroup STM32WBxx_HAL_Driver
38   * @{
39   */
40 
41 /** @addtogroup HAL
42   * @brief HAL module driver
43   * @{
44   */
45 
46 #ifdef HAL_MODULE_ENABLED
47 
48 /* Private typedef -----------------------------------------------------------*/
49 /* Private define ------------------------------------------------------------*/
50 
51 /** @defgroup HAL_Private_Constants HAL Private Constants
52   * @{
53   */
54 /**
55   * @brief STM32WBxx HAL Driver version number
56    */
57 #define __STM32WBxx_HAL_VERSION_MAIN   (0x01U) /*!< [31:24] main version */
58 #define __STM32WBxx_HAL_VERSION_SUB1   (0x0EU) /*!< [23:16] sub1 version */
59 #define __STM32WBxx_HAL_VERSION_SUB2   (0x03U) /*!< [15:8]  sub2 version */
60 #define __STM32WBxx_HAL_VERSION_RC     (0x00U) /*!< [7:0]  release candidate */
61 #define __STM32WBxx_HAL_VERSION         ((__STM32WBxx_HAL_VERSION_MAIN << 24U)\
62                                          |(__STM32WBxx_HAL_VERSION_SUB1 << 16U)\
63                                          |(__STM32WBxx_HAL_VERSION_SUB2 << 8U )\
64                                          |(__STM32WBxx_HAL_VERSION_RC))
65 
66 #if defined(VREFBUF)
67 #define VREFBUF_TIMEOUT_VALUE     10U   /* 10 ms */
68 #endif /* VREFBUF */
69 
70 /**
71   * @}
72   */
73 
74 /* Private macro -------------------------------------------------------------*/
75 /* Exported variables ---------------------------------------------------------*/
76 /** @defgroup HAL_Exported_Variables HAL Exported Variables
77   * @{
78   */
79 __IO uint32_t uwTick;
80 uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
81 HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT;  /* 1KHz */
82 /**
83   * @}
84   */
85 
86 /* Private function prototypes -----------------------------------------------*/
87 /* Exported functions --------------------------------------------------------*/
88 
89 /** @addtogroup HAL_Exported_Functions
90   * @{
91   */
92 
93 /** @addtogroup HAL_Exported_Functions_Group1
94   *  @brief    HAL Initialization and Configuration functions
95   *
96 @verbatim
97  ===============================================================================
98            ##### HAL Initialization and Configuration functions #####
99  ===============================================================================
100     [..]  This section provides functions allowing to:
101       (+) Initialize the Flash interface the NVIC allocation and initial time base
102           clock configuration.
103       (+) De-initialize common part of the HAL.
104       (+) Configure the time base source to have 1ms time base with a dedicated
105           Tick interrupt priority.
106         (++) SysTick timer is used by default as source of time base, but user
107              can eventually implement his proper time base source (a general purpose
108              timer for example or other time source), keeping in mind that Time base
109              duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
110              handled in milliseconds basis.
111         (++) Time base configuration function (HAL_InitTick ()) is called automatically
112              at the beginning of the program after reset by HAL_Init() or at any time
113              when clock is configured, by HAL_RCC_ClockConfig().
114         (++) Source of time base is configured  to generate interrupts at regular
115              time intervals. Care must be taken if HAL_Delay() is called from a
116              peripheral ISR process, the Tick interrupt line must have higher priority
117             (numerically lower) than the peripheral interrupt. Otherwise the caller
118             ISR process will be blocked.
119        (++) functions affecting time base configurations are declared as __weak
120              to make  override possible  in case of other  implementations in user file.
121 @endverbatim
122   * @{
123   */
124 
125 /**
126   * @brief  This function is used to initialize the HAL Library; it must be the first
127   *         instruction to be executed in the main program (before to call any other
128   *         HAL function), it performs the following:
129   *           Configure the Flash prefetch, instruction and Data caches.
130   *           Configures the SysTick to generate an interrupt each 1 millisecond,
131   *           which is clocked by the MSI (at this stage, the clock is not yet
132   *           configured and thus the system is running from the internal MSI at 4 MHz).
133   *           Set NVIC Group Priority to 4.
134   *           Calls the HAL_MspInit() callback function defined in user file
135   *           "stm32wbxx_hal_msp.c" to do the global low level hardware initialization
136   *
137   * @note   SysTick is used as time base for the HAL_Delay() function, the application
138   *         need to ensure that the SysTick time base is always set to 1 millisecond
139   *         to have correct HAL operation.
140   * @retval HAL status
141   */
HAL_Init(void)142 HAL_StatusTypeDef HAL_Init(void)
143 {
144   HAL_StatusTypeDef  status = HAL_OK;
145   /* Configure Flash prefetch, Instruction cache, Data cache */
146   /* Default configuration at reset is:                      */
147   /* - Prefetch disabled                                     */
148   /* - Instruction cache enabled                             */
149   /* - Data cache enabled                                    */
150 #if (INSTRUCTION_CACHE_ENABLE == 0U)
151   __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
152 #endif /* INSTRUCTION_CACHE_ENABLE */
153 
154 #if (DATA_CACHE_ENABLE == 0U)
155   __HAL_FLASH_DATA_CACHE_DISABLE();
156 #endif /* DATA_CACHE_ENABLE */
157 
158 #if (PREFETCH_ENABLE != 0U)
159   __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
160 #endif /* PREFETCH_ENABLE */
161 
162   /* Set Interrupt Group Priority */
163   HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
164 
165   /* Use SysTick as time base source and configure 1ms tick (default clock after Reset is MSI) */
166   if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
167   {
168     status = HAL_ERROR;
169   }
170   else
171   {
172     /* Init the low level hardware */
173     HAL_MspInit();
174   }
175 
176   /* Return function status */
177   return status;
178 }
179 
180 /**
181   * @brief  This function de-Initializes common part of the HAL and stops the source of time base.
182   * @note   This function is optional.
183   * @retval HAL status
184   */
HAL_DeInit(void)185 HAL_StatusTypeDef HAL_DeInit(void)
186 {
187   /* Reset of all peripherals */
188   __HAL_RCC_APB1_FORCE_RESET();
189   __HAL_RCC_APB1_RELEASE_RESET();
190 
191   __HAL_RCC_APB2_FORCE_RESET();
192   __HAL_RCC_APB2_RELEASE_RESET();
193 
194   __HAL_RCC_APB3_FORCE_RESET();
195   __HAL_RCC_APB3_RELEASE_RESET();
196 
197   __HAL_RCC_AHB1_FORCE_RESET();
198   __HAL_RCC_AHB1_RELEASE_RESET();
199 
200   __HAL_RCC_AHB2_FORCE_RESET();
201   __HAL_RCC_AHB2_RELEASE_RESET();
202 
203   __HAL_RCC_AHB3_FORCE_RESET();
204   __HAL_RCC_AHB3_RELEASE_RESET();
205 
206   /* De-Init the low level hardware */
207   HAL_MspDeInit();
208 
209   /* Return function status */
210   return HAL_OK;
211 }
212 
213 /**
214   * @brief  Initialize the MSP.
215   * @retval None
216   */
HAL_MspInit(void)217 __weak void HAL_MspInit(void)
218 {
219   /* NOTE : This function should not be modified, when the callback is needed,
220             the HAL_MspInit could be implemented in the user file
221    */
222 }
223 
224 /**
225   * @brief  DeInitializes the MSP.
226   * @retval None
227   */
HAL_MspDeInit(void)228 __weak void HAL_MspDeInit(void)
229 {
230   /* NOTE : This function should not be modified, when the callback is needed,
231             the HAL_MspDeInit could be implemented in the user file
232    */
233 }
234 
235 /**
236   * @brief This function configures the source of the time base:
237   *        The time source is configured  to have 1ms time base with a dedicated
238   *        Tick interrupt priority.
239   * @note This function is called  automatically at the beginning of program after
240   *       reset by HAL_Init() or at any time when clock is reconfigured  by HAL_RCC_ClockConfig().
241   * @note In the default implementation, SysTick timer is the source of time base.
242   *       It is used to generate interrupts at regular time intervals.
243   *       Care must be taken if HAL_Delay() is called from a peripheral ISR process,
244   *       The SysTick interrupt must have higher priority (numerically lower)
245   *       than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
246   *       The function is declared as __weak  to be overwritten  in case of other
247   *       implementation  in user file.
248   * @param TickPriority Tick interrupt priority.
249   * @retval HAL status
250   */
HAL_InitTick(uint32_t TickPriority)251 __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
252 {
253   HAL_StatusTypeDef  status = HAL_OK;
254 
255   if ((uint32_t)uwTickFreq != 0U)
256   {
257     /*Configure the SysTick to have interrupt in 1ms time basis*/
258     if (HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / (1000U / (uint32_t)uwTickFreq)) == 0U)
259     {
260       /* Configure the SysTick IRQ priority */
261       if (TickPriority < (1UL << __NVIC_PRIO_BITS))
262       {
263         HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
264         uwTickPrio = TickPriority;
265       }
266       else
267       {
268         status = HAL_ERROR;
269       }
270     }
271     else
272     {
273       status = HAL_ERROR;
274     }
275   }
276   else
277   {
278     status = HAL_ERROR;
279   }
280 
281   /* Return function status */
282   return status;
283 }
284 
285 /**
286   * @}
287   */
288 
289 /** @addtogroup HAL_Exported_Functions_Group2
290   *  @brief    HAL Control functions
291   *
292 @verbatim
293  ===============================================================================
294                       ##### HAL Control functions #####
295  ===============================================================================
296     [..]  This section provides functions allowing to:
297       (+) Provide a tick value in millisecond
298       (+) Provide a blocking delay in millisecond
299       (+) Suspend the time base source interrupt
300       (+) Resume the time base source interrupt
301       (+) Get the HAL API driver version
302       (+) Get the device revision identifier
303       (+) Get the device identifier
304       (+) Get the unique device identifier
305 
306 @endverbatim
307   * @{
308   */
309 
310 /**
311   * @brief This function is called to increment  a global variable "uwTick"
312   *        used as application time base.
313   * @note In the default implementation, this variable is incremented each 1ms
314   *       in SysTick ISR.
315   * @note This function is declared as __weak to be overwritten in case of other
316   *      implementations in user file.
317   * @retval None
318   */
HAL_IncTick(void)319 __weak void HAL_IncTick(void)
320 {
321   uwTick += (uint32_t)uwTickFreq;
322 }
323 
324 /**
325   * @brief Provides a tick value in millisecond.
326   * @note This function is declared as __weak to be overwritten in case of other
327   *       implementations in user file.
328   * @retval tick value
329   */
HAL_GetTick(void)330 __weak uint32_t HAL_GetTick(void)
331 {
332   return uwTick;
333 }
334 
335 /**
336   * @brief This function returns a tick priority.
337   * @retval tick priority
338   */
HAL_GetTickPrio(void)339 uint32_t HAL_GetTickPrio(void)
340 {
341   return uwTickPrio;
342 }
343 
344 /**
345   * @brief Set new tick Freq.
346   * @retval Status
347   */
HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)348 HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
349 {
350   HAL_StatusTypeDef status  = HAL_OK;
351   HAL_TickFreqTypeDef prevTickFreq;
352 
353   assert_param(IS_TICKFREQ(Freq));
354 
355   if (uwTickFreq != Freq)
356   {
357     /* Back up uwTickFreq frequency */
358     prevTickFreq = uwTickFreq;
359 
360     /* Update uwTickFreq global variable used by HAL_InitTick() */
361     uwTickFreq = Freq;
362 
363     /* Apply the new tick Freq */
364     status = HAL_InitTick(uwTickPrio);
365 
366     if (status != HAL_OK)
367     {
368       /* Restore previous tick frequency */
369       uwTickFreq = prevTickFreq;
370     }
371   }
372 
373   return status;
374 }
375 
376 /**
377   * @brief Return tick frequency.
378   * @retval Tick frequency.
379   *         Value of @ref HAL_TickFreqTypeDef.
380   */
HAL_GetTickFreq(void)381 HAL_TickFreqTypeDef HAL_GetTickFreq(void)
382 {
383   return uwTickFreq;
384 }
385 
386 /**
387   * @brief This function provides minimum delay (in milliseconds) based
388   *        on variable incremented.
389   * @note In the default implementation , SysTick timer is the source of time base.
390   *       It is used to generate interrupts at regular time intervals where uwTick
391   *       is incremented.
392   * @note This function is declared as __weak to be overwritten in case of other
393   *       implementations in user file.
394   * @param Delay  specifies the delay time length, in milliseconds.
395   * @retval None
396   */
HAL_Delay(uint32_t Delay)397 __weak void HAL_Delay(uint32_t Delay)
398 {
399   uint32_t tickstart = HAL_GetTick();
400   uint32_t wait = Delay;
401 
402   /* Add a freq to guarantee minimum wait */
403   if (wait < HAL_MAX_DELAY)
404   {
405     wait += (uint32_t)(uwTickFreq);
406   }
407 
408   while ((HAL_GetTick() - tickstart) < wait)
409   {
410   }
411 }
412 
413 
414 /**
415   * @brief Suspend Tick increment.
416   * @note In the default implementation , SysTick timer is the source of time base. It is
417   *       used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
418   *       is called, the SysTick interrupt will be disabled and so Tick increment
419   *       is suspended.
420   * @note This function is declared as __weak to be overwritten in case of other
421   *       implementations in user file.
422   * @retval None
423   */
HAL_SuspendTick(void)424 __weak void HAL_SuspendTick(void)
425 {
426   /* Disable SysTick Interrupt */
427   CLEAR_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
428 }
429 
430 /**
431   * @brief Resume Tick increment.
432   * @note In the default implementation , SysTick timer is the source of time base. It is
433   *       used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
434   *       is called, the SysTick interrupt will be enabled and so Tick increment
435   *       is resumed.
436   * @note This function is declared as __weak to be overwritten in case of other
437   *       implementations in user file.
438   * @retval None
439   */
HAL_ResumeTick(void)440 __weak void HAL_ResumeTick(void)
441 {
442   /* Enable SysTick Interrupt */
443   SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
444 }
445 
446 /**
447   * @brief  Returns the HAL revision
448   * @retval version : 0xXYZR (8bits for each decimal, R for RC)
449   */
HAL_GetHalVersion(void)450 uint32_t HAL_GetHalVersion(void)
451 {
452   return __STM32WBxx_HAL_VERSION;
453 }
454 
455 /**
456   * @brief  Returns the device revision identifier.
457   * @retval Device revision identifier
458   */
HAL_GetREVID(void)459 uint32_t HAL_GetREVID(void)
460 {
461   return (LL_DBGMCU_GetRevisionID());
462 }
463 
464 /**
465   * @brief  Returns the device identifier.
466   * @retval Device identifier
467   */
HAL_GetDEVID(void)468 uint32_t HAL_GetDEVID(void)
469 {
470   return (LL_DBGMCU_GetDeviceID());
471 }
472 
473 /**
474   * @brief  Return the first word of the unique device identifier (UID based on 96 bits)
475   * @retval Device identifier
476   */
HAL_GetUIDw0(void)477 uint32_t HAL_GetUIDw0(void)
478 {
479   return (READ_REG(*((uint32_t *)UID_BASE)));
480 }
481 
482 /**
483   * @brief  Return the second word of the unique device identifier (UID based on 96 bits)
484   * @retval Device identifier
485   */
HAL_GetUIDw1(void)486 uint32_t HAL_GetUIDw1(void)
487 {
488   return (READ_REG(*((uint32_t *)(UID_BASE + 4U))));
489 }
490 
491 /**
492   * @brief  Return the third word of the unique device identifier (UID based on 96 bits)
493   * @retval Device identifier
494   */
HAL_GetUIDw2(void)495 uint32_t HAL_GetUIDw2(void)
496 {
497   return (READ_REG(*((uint32_t *)(UID_BASE + 8U))));
498 }
499 
500 /**
501   * @}
502   */
503 
504 /** @addtogroup HAL_Exported_Functions_Group3
505   *  @brief    HAL Debug functions
506   *
507 @verbatim
508  ===============================================================================
509                       ##### HAL Debug functions #####
510  ===============================================================================
511     [..]  This section provides functions allowing to:
512       (+) Enable/Disable Debug module during SLEEP mode
513       (+) Enable/Disable Debug module during STOP mode
514       (+) Enable/Disable Debug module during STANDBY mode
515 
516 @endverbatim
517   * @{
518   */
519 
520 /**
521   * @brief  Enable the Debug Module during SLEEP mode
522   * @retval None
523   */
HAL_DBGMCU_EnableDBGSleepMode(void)524 void HAL_DBGMCU_EnableDBGSleepMode(void)
525 {
526   LL_DBGMCU_EnableDBGSleepMode();
527 }
528 
529 /**
530   * @brief  Disable the Debug Module during SLEEP mode
531   * @retval None
532   */
HAL_DBGMCU_DisableDBGSleepMode(void)533 void HAL_DBGMCU_DisableDBGSleepMode(void)
534 {
535   LL_DBGMCU_DisableDBGSleepMode();
536 }
537 
538 /**
539   * @brief  Enable the Debug Module during STOP mode
540   * @retval None
541   */
HAL_DBGMCU_EnableDBGStopMode(void)542 void HAL_DBGMCU_EnableDBGStopMode(void)
543 {
544   LL_DBGMCU_EnableDBGStopMode();
545 }
546 
547 /**
548   * @brief  Disable the Debug Module during STOP mode
549   * @retval None
550   */
HAL_DBGMCU_DisableDBGStopMode(void)551 void HAL_DBGMCU_DisableDBGStopMode(void)
552 {
553   LL_DBGMCU_DisableDBGStopMode();
554 }
555 
556 /**
557   * @brief  Enable the Debug Module during STANDBY mode
558   * @retval None
559   */
HAL_DBGMCU_EnableDBGStandbyMode(void)560 void HAL_DBGMCU_EnableDBGStandbyMode(void)
561 {
562   LL_DBGMCU_EnableDBGStandbyMode();
563 }
564 
565 /**
566   * @brief  Disable the Debug Module during STANDBY mode
567   * @retval None
568   */
HAL_DBGMCU_DisableDBGStandbyMode(void)569 void HAL_DBGMCU_DisableDBGStandbyMode(void)
570 {
571   LL_DBGMCU_DisableDBGStandbyMode();
572 }
573 
574 /**
575   * @}
576   */
577 
578 /** @defgroup HAL_Exported_Functions_Group4 HAL System Configuration functions
579   *  @brief    HAL System Configuration functions
580   *
581 @verbatim
582  ===============================================================================
583                  ##### HAL system configuration functions #####
584  ===============================================================================
585     [..]  This section provides functions allowing to:
586       (+) Start a hardware SRAM2 erase operation
587       (+) Disable CPU2 SRAM fetch (execution)
588       (+) Configure the Voltage reference buffer
589       (+) Enable/Disable the Voltage reference buffer
590       (+) Enable/Disable the I/O analog switch voltage booster
591       (+) Enable/Disable the access for security IP (AES1, AES2, PKA, RNG)
592       (+) Enable/Disable the access for security IP (AES2, PKA, RNG)
593 
594 @endverbatim
595   * @{
596   */
597 
598 /**
599   * @brief  Start a hardware SRAM2 erase operation.
600   * @note   As long as SRAM2 is not erased the SRAM2ER bit will be set.
601   *         This bit is automatically reset at the end of the SRAM2 erase operation.
602   * @retval None
603   */
HAL_SYSCFG_SRAM2Erase(void)604 void HAL_SYSCFG_SRAM2Erase(void)
605 {
606   /* unlock the write protection of the SRAM2ER bit */
607   __HAL_SYSCFG_SRAM2_WRP_UNLOCK();
608   /* Starts a hardware SRAM2 erase operation*/
609   __HAL_SYSCFG_SRAM2_ERASE();
610 }
611 
612 /**
613   * @brief  Disable CPU2 SRAM fetch (execution) (This bit can be set by Firmware
614   *         and will only be reset by a Hardware reset, including a reset after Standby.)
615   * @note Firmware writing 0 has no effect.
616   * @retval None
617   */
HAL_SYSCFG_DisableSRAMFetch(void)618 void HAL_SYSCFG_DisableSRAMFetch(void)
619 {
620   LL_SYSCFG_DisableSRAMFetch();
621 }
622 
623 /**
624   * @brief  Check if CPU2 SRAM fetch is enabled
625   * @retval State of bit (1 or 0).
626   */
HAL_SYSCFG_IsEnabledSRAMFetch(void)627 uint32_t HAL_SYSCFG_IsEnabledSRAMFetch(void)
628 {
629   return (LL_SYSCFG_IsEnabledSRAMFetch());
630 }
631 
632 #if defined(VREFBUF)
633 /**
634   * @brief Configure the internal voltage reference buffer voltage scale.
635   * @param VoltageScaling  specifies the output voltage to achieve
636   *          This parameter can be one of the following values:
637   *            @arg @ref SYSCFG_VREFBUF_VOLTAGE_SCALE0 : VREF_OUT1 around 2.048 V.
638   *                                                This requires VDDA equal to or higher than 2.4 V.
639   *            @arg @ref SYSCFG_VREFBUF_VOLTAGE_SCALE1 : VREF_OUT1 around 2.5 V.
640   *                                                This requires VDDA equal to or higher than 2.8 V.
641   * @note   Retrieve the TrimmingValue from factory located at
642   *         VREFBUF_SC0_CAL_ADDR or VREFBUF_SC1_CAL_ADDR addresses.
643   * @retval None
644   */
HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)645 void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)
646 {
647   uint32_t TrimmingValue;
648 
649   /* Check the parameters */
650   assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling));
651 
652   LL_VREFBUF_SetVoltageScaling(VoltageScaling);
653 
654   /* Restrieve Calibration data and store them into trimming field */
655   if (VoltageScaling == SYSCFG_VREFBUF_VOLTAGE_SCALE0)
656   {
657     TrimmingValue = ((uint32_t) * VREFBUF_SC0_CAL_ADDR) & 0x3FU;
658   }
659   else
660   {
661     TrimmingValue = ((uint32_t) * VREFBUF_SC1_CAL_ADDR) & 0x3FU;
662   }
663   assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
664 
665   HAL_SYSCFG_VREFBUF_TrimmingConfig(TrimmingValue);
666 }
667 
668 /**
669   * @brief Configure the internal voltage reference buffer high impedance mode.
670   * @param Mode  specifies the high impedance mode
671   *          This parameter can be one of the following values:
672   *            @arg @ref SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE : VREF+ pin is internally connect to VREFINT output.
673   *            @arg @ref SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE : VREF+ pin is high impedance.
674   * @retval HAL_OK/HAL_TIMEOUT
675   */
HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)676 void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)
677 {
678 
679   /* Check the parameters */
680   assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode));
681 
682   MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode);
683 }
684 
685 /**
686   * @brief Tune the Internal Voltage Reference buffer (VREFBUF).
687   * @note  Each VrefBuf voltage scale is calibrated in production for each device,
688   *        data stored in flash memory.
689   *        Function @ref HAL_SYSCFG_VREFBUF_VoltageScalingConfig retrieves and
690   *        applies this calibration data as trimming value at each scale change.
691   *        Therefore, optionally, function @ref HAL_SYSCFG_VREFBUF_TrimmingConfig
692   *        can be used in a second time to fine tune the trimming.
693   * @param TrimmingValue specifies trimming code for VREFBUF calibration
694   *          This parameter can be a number between Min_Data = 0x00 and Max_Data = 0x3F
695   * @retval None
696   */
HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)697 void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)
698 {
699   /* Check the parameters */
700   assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
701 
702   LL_VREFBUF_SetTrimming(TrimmingValue);
703 
704 }
705 
706 /**
707   * @brief  Enable the Internal Voltage Reference buffer (VREFBUF).
708   * @retval HAL_OK/HAL_TIMEOUT
709   */
HAL_SYSCFG_EnableVREFBUF(void)710 HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void)
711 {
712   uint32_t tickstart;
713 
714   LL_VREFBUF_Enable();
715 
716   /* Get Start Tick*/
717   tickstart = HAL_GetTick();
718 
719   /* Wait for VRR bit  */
720   while (READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == 0U)
721   {
722     if ((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE)
723     {
724       return HAL_TIMEOUT;
725     }
726   }
727 
728   return HAL_OK;
729 }
730 
731 /**
732   * @brief  Disable the Internal Voltage Reference buffer (VREFBUF).
733   *
734   * @retval None
735   */
HAL_SYSCFG_DisableVREFBUF(void)736 void HAL_SYSCFG_DisableVREFBUF(void)
737 {
738   LL_VREFBUF_Disable();
739 }
740 #endif /* VREFBUF */
741 
742 /**
743   * @brief  Enable the I/O analog switch voltage booster
744   *
745   * @retval None
746   */
HAL_SYSCFG_EnableIOBooster(void)747 void HAL_SYSCFG_EnableIOBooster(void)
748 {
749   LL_SYSCFG_EnableAnalogBooster();
750 }
751 
752 /**
753   * @brief  Disable the I/O analog switch voltage booster
754   *
755   * @retval None
756   */
HAL_SYSCFG_DisableIOBooster(void)757 void HAL_SYSCFG_DisableIOBooster(void)
758 {
759   LL_SYSCFG_DisableAnalogBooster();
760 }
761 
762 #if defined(SYSCFG_CFGR1_ANASWVDD)
763 /**
764   * @brief  Enable the I/O analog switch supplied by VDD
765   * @note   To be used when I/O analog switch voltage booster is not enabled
766   * @retval None
767   */
HAL_SYSCFG_EnableIOVdd(void)768 void HAL_SYSCFG_EnableIOVdd(void)
769 {
770   LL_SYSCFG_EnableAnalogGpioSwitch();
771 }
772 
773 /**
774   * @brief  Disable the I/O analog switch supplied by VDD
775   *
776   * @retval None
777   */
HAL_SYSCFG_DisableIOVdd(void)778 void HAL_SYSCFG_DisableIOVdd(void)
779 {
780   LL_SYSCFG_DisableAnalogGpioSwitch();
781 }
782 #endif /* SYSCFG_CFGR1_ANASWVDD */
783 
784 /**
785   * @brief  Enable the access for security IP
786   * @note   When the system is secure (ESE = 1), this register provides write access security and can
787   *         only be written by the CPU2. A write access from the CPU1 will be ignored and a bus error
788   *         is generated.
789   * @param  SecurityAccess This parameter can be a combination of the following values:
790   *         @arg @ref HAL_SYSCFG_SECURE_ACCESS_AES1
791   *         @arg @ref HAL_SYSCFG_SECURE_ACCESS_AES2
792   *         @arg @ref HAL_SYSCFG_SECURE_ACCESS_PKA
793   *         @arg @ref HAL_SYSCFG_SECURE_ACCESS_RNG
794   * @retval None
795   */
HAL_SYSCFG_EnableSecurityAccess(uint32_t SecurityAccess)796 void HAL_SYSCFG_EnableSecurityAccess(uint32_t SecurityAccess)
797 {
798   /* Check the parameters */
799   assert_param(IS_SYSCFG_SECURITY_ACCESS(SecurityAccess));
800 
801   LL_SYSCFG_EnableSecurityAccess(SecurityAccess);
802 }
803 
804 /**
805   * @brief  Disable the access for security IP
806   * @note   When the system is secure (ESE = 1), this register provides write access security and can
807   *         only be written by the CPU2. A write access from the CPU1 will be ignored and a bus error
808   *         is generated.
809   * @param  SecurityAccess This parameter can be a combination of the following values:
810   *         @arg @ref HAL_SYSCFG_SECURE_ACCESS_AES1
811   *         @arg @ref HAL_SYSCFG_SECURE_ACCESS_AES2
812   *         @arg @ref HAL_SYSCFG_SECURE_ACCESS_PKA
813   *         @arg @ref HAL_SYSCFG_SECURE_ACCESS_RNG
814   * @retval None
815   */
HAL_SYSCFG_DisableSecurityAccess(uint32_t SecurityAccess)816 void HAL_SYSCFG_DisableSecurityAccess(uint32_t SecurityAccess)
817 {
818   /* Check the parameters */
819   assert_param(IS_SYSCFG_SECURITY_ACCESS(SecurityAccess));
820 
821   LL_SYSCFG_DisableSecurityAccess(SecurityAccess);
822 }
823 
824 /**
825   * @brief  Indicate if access for security IP is enabled
826   * @param  SecurityAccess This parameter can be one of the following values:
827   *         @arg @ref HAL_SYSCFG_SECURE_ACCESS_AES1
828   *         @arg @ref HAL_SYSCFG_SECURE_ACCESS_AES2
829   *         @arg @ref HAL_SYSCFG_SECURE_ACCESS_PKA
830   *         @arg @ref HAL_SYSCFG_SECURE_ACCESS_RNG
831   * @retval State of bit (1 or 0).
832   */
HAL_SYSCFG_IsEnabledSecurityAccess(uint32_t SecurityAccess)833 uint32_t HAL_SYSCFG_IsEnabledSecurityAccess(uint32_t SecurityAccess)
834 {
835   return (LL_SYSCFG_IsEnabledSecurityAccess(SecurityAccess));
836 }
837 /**
838   * @}
839   */
840 
841 /**
842   * @}
843   */
844 
845 #endif /* HAL_MODULE_ENABLED */
846 /**
847   * @}
848   */
849 
850 /**
851   * @}
852   */
853