stm32l4xx_hal.c 22 KB

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