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