stm32l4xx_hal.c 22 KB

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