stm32l4xx_hal.c 22 KB

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