stm32l4xx_hal.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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 (0x01) /*!< [31:24] main version */
  65. #define __STM32L4xx_HAL_VERSION_SUB1 (0x08) /*!< [23:16] sub1 version */
  66. #define __STM32L4xx_HAL_VERSION_SUB2 (0x02) /*!< [15:8] sub2 version */
  67. #define __STM32L4xx_HAL_VERSION_RC (0x00) /*!< [7:0] release candidate */
  68. #define __STM32L4xx_HAL_VERSION ((__STM32L4xx_HAL_VERSION_MAIN << 24)\
  69. |(__STM32L4xx_HAL_VERSION_SUB1 << 16)\
  70. |(__STM32L4xx_HAL_VERSION_SUB2 << 8 )\
  71. |(__STM32L4xx_HAL_VERSION_RC))
  72. #if defined(VREFBUF)
  73. #define VREFBUF_TIMEOUT_VALUE (uint32_t)10 /* 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 ((uint8_t)0x8)
  81. #define FB_MODE_BB (PERIPH_BB_BASE + (MEMRMP_OFFSET * 32) + (FB_MODE_BitNumber * 4))
  82. /* --- SCSR Register ---*/
  83. /* Alias word address of SRAM2ER bit */
  84. #define SCSR_OFFSET (SYSCFG_OFFSET + 0x18)
  85. #define BRER_BitNumber ((uint8_t)0x0)
  86. #define SCSR_SRAM2ER_BB (PERIPH_BB_BASE + (SCSR_OFFSET * 32) + (BRER_BitNumber * 4))
  87. /* Private macro -------------------------------------------------------------*/
  88. /* Private variables ---------------------------------------------------------*/
  89. __IO uint32_t uwTick;
  90. /* Private function prototypes -----------------------------------------------*/
  91. /* Exported functions --------------------------------------------------------*/
  92. /** @defgroup HAL_Exported_Functions HAL Exported Functions
  93. * @{
  94. */
  95. /** @defgroup HAL_Exported_Functions_Group1 Initialization and de-initialization Functions
  96. * @brief Initialization and de-initialization functions
  97. *
  98. @verbatim
  99. ===============================================================================
  100. ##### Initialization and de-initialization functions #####
  101. ===============================================================================
  102. [..] This section provides functions allowing to:
  103. (+) Initialize the Flash interface the NVIC allocation and initial time base
  104. clock configuration.
  105. (+) De-initialize common part of the HAL.
  106. (+) Configure the time base source to have 1ms time base with a dedicated
  107. Tick interrupt priority.
  108. (++) SysTick timer is used by default as source of time base, but user
  109. can eventually implement his proper time base source (a general purpose
  110. timer for example or other time source), keeping in mind that Time base
  111. duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
  112. handled in milliseconds basis.
  113. (++) Time base configuration function (HAL_InitTick ()) is called automatically
  114. at the beginning of the program after reset by HAL_Init() or at any time
  115. when clock is configured, by HAL_RCC_ClockConfig().
  116. (++) Source of time base is configured to generate interrupts at regular
  117. time intervals. Care must be taken if HAL_Delay() is called from a
  118. peripheral ISR process, the Tick interrupt line must have higher priority
  119. (numerically lower) than the peripheral interrupt. Otherwise the caller
  120. ISR process will be blocked.
  121. (++) functions affecting time base configurations are declared as __weak
  122. to make override possible in case of other implementations in user file.
  123. @endverbatim
  124. * @{
  125. */
  126. /**
  127. * @brief Configure the Flash prefetch, the Instruction and Data caches,
  128. * the time base source, NVIC and any required global low level hardware
  129. * by calling the HAL_MspInit() callback function to be optionally defined in user file
  130. * stm32l4xx_hal_msp.c.
  131. *
  132. * @note HAL_Init() function is called at the beginning of program after reset and before
  133. * the clock configuration.
  134. *
  135. * @note In the default implementation the System Timer (Systick) is used as source of time base.
  136. * The Systick configuration is based on MSI clock, as MSI is the clock
  137. * used after a system Reset and the NVIC configuration is set to Priority group 4.
  138. * Once done, time base tick starts incrementing: the tick variable counter is incremented
  139. * each 1ms in the SysTick_Handler() interrupt handler.
  140. *
  141. * @retval HAL status
  142. */
  143. HAL_StatusTypeDef HAL_Init(void)
  144. {
  145. /* Configure Flash prefetch, Instruction cache, Data cache */
  146. /* Default configuration at reset is: */
  147. /* - Prefetch disabled */
  148. /* - Instruction cache enabled */
  149. /* - Data cache enabled */
  150. #if (INSTRUCTION_CACHE_ENABLE == 0)
  151. __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
  152. #endif /* INSTRUCTION_CACHE_ENABLE */
  153. #if (DATA_CACHE_ENABLE == 0)
  154. __HAL_FLASH_DATA_CACHE_DISABLE();
  155. #endif /* DATA_CACHE_ENABLE */
  156. #if (PREFETCH_ENABLE != 0)
  157. __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
  158. #endif /* PREFETCH_ENABLE */
  159. /* Set Interrupt Group Priority */
  160. HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
  161. /* Use SysTick as time base source and configure 1ms tick (default clock after Reset is MSI) */
  162. HAL_InitTick(TICK_INT_PRIORITY);
  163. /* Init the low level hardware */
  164. HAL_MspInit();
  165. /* Return function status */
  166. return HAL_OK;
  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. /*Configure the SysTick to have interrupt in 1ms time basis*/
  230. HAL_SYSTICK_Config(SystemCoreClock/1000);
  231. /*Configure the SysTick IRQ priority */
  232. HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority ,0);
  233. /* Return function status */
  234. return HAL_OK;
  235. }
  236. /**
  237. * @}
  238. */
  239. /** @defgroup HAL_Exported_Functions_Group2 HAL Control functions
  240. * @brief HAL Control functions
  241. *
  242. @verbatim
  243. ===============================================================================
  244. ##### HAL Control functions #####
  245. ===============================================================================
  246. [..] This section provides functions allowing to:
  247. (+) Provide a tick value in millisecond
  248. (+) Provide a blocking delay in millisecond
  249. (+) Suspend the time base source interrupt
  250. (+) Resume the time base source interrupt
  251. (+) Get the HAL API driver version
  252. (+) Get the device identifier
  253. (+) Get the device revision identifier
  254. @endverbatim
  255. * @{
  256. */
  257. /**
  258. * @brief This function is called to increment a global variable "uwTick"
  259. * used as application time base.
  260. * @note In the default implementation, this variable is incremented each 1ms
  261. * in SysTick ISR.
  262. * @note This function is declared as __weak to be overwritten in case of other
  263. * implementations in user file.
  264. * @retval None
  265. */
  266. __weak void HAL_IncTick(void)
  267. {
  268. uwTick++;
  269. }
  270. /**
  271. * @brief Provide a tick value in millisecond.
  272. * @note This function is declared as __weak to be overwritten in case of other
  273. * implementations in user file.
  274. * @retval tick value
  275. */
  276. __weak uint32_t HAL_GetTick(void)
  277. {
  278. return uwTick;
  279. }
  280. /**
  281. * @brief This function provides minimum delay (in milliseconds) based
  282. * on variable incremented.
  283. * @note In the default implementation , SysTick timer is the source of time base.
  284. * It is used to generate interrupts at regular time intervals where uwTick
  285. * is incremented.
  286. * @note This function is declared as __weak to be overwritten in case of other
  287. * implementations in user file.
  288. * @param Delay specifies the delay time length, in milliseconds.
  289. * @retval None
  290. */
  291. __weak void HAL_Delay(uint32_t Delay)
  292. {
  293. uint32_t tickstart = HAL_GetTick();
  294. uint32_t wait = Delay;
  295. /* Add a period to guaranty minimum wait */
  296. if (wait < HAL_MAX_DELAY)
  297. {
  298. wait++;
  299. }
  300. while((HAL_GetTick() - tickstart) < wait)
  301. {
  302. }
  303. }
  304. /**
  305. * @brief Suspend Tick increment.
  306. * @note In the default implementation , SysTick timer is the source of time base. It is
  307. * used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
  308. * is called, the SysTick interrupt will be disabled and so Tick increment
  309. * is suspended.
  310. * @note This function is declared as __weak to be overwritten in case of other
  311. * implementations in user file.
  312. * @retval None
  313. */
  314. __weak void HAL_SuspendTick(void)
  315. {
  316. /* Disable SysTick Interrupt */
  317. SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
  318. }
  319. /**
  320. * @brief Resume Tick increment.
  321. * @note In the default implementation , SysTick timer is the source of time base. It is
  322. * used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
  323. * is called, the SysTick interrupt will be enabled and so Tick increment
  324. * is resumed.
  325. * @note This function is declared as __weak to be overwritten in case of other
  326. * implementations in user file.
  327. * @retval None
  328. */
  329. __weak void HAL_ResumeTick(void)
  330. {
  331. /* Enable SysTick Interrupt */
  332. SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
  333. }
  334. /**
  335. * @brief Return the HAL revision.
  336. * @retval version : 0xXYZR (8bits for each decimal, R for RC)
  337. */
  338. uint32_t HAL_GetHalVersion(void)
  339. {
  340. return __STM32L4xx_HAL_VERSION;
  341. }
  342. /**
  343. * @brief Return the device revision identifier.
  344. * @retval Device revision identifier
  345. */
  346. uint32_t HAL_GetREVID(void)
  347. {
  348. return((DBGMCU->IDCODE & DBGMCU_IDCODE_REV_ID) >> 16);
  349. }
  350. /**
  351. * @brief Return the device identifier.
  352. * @retval Device identifier
  353. */
  354. uint32_t HAL_GetDEVID(void)
  355. {
  356. return(DBGMCU->IDCODE & DBGMCU_IDCODE_DEV_ID);
  357. }
  358. /**
  359. * @brief Return the first word of the unique device identifier (UID based on 96 bits)
  360. * @retval Device identifier
  361. */
  362. uint32_t HAL_GetUIDw0(void)
  363. {
  364. return(READ_REG(*((uint32_t *)UID_BASE)));
  365. }
  366. /**
  367. * @brief Return the second word of the unique device identifier (UID based on 96 bits)
  368. * @retval Device identifier
  369. */
  370. uint32_t HAL_GetUIDw1(void)
  371. {
  372. return(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
  373. }
  374. /**
  375. * @brief Return the third word of the unique device identifier (UID based on 96 bits)
  376. * @retval Device identifier
  377. */
  378. uint32_t HAL_GetUIDw2(void)
  379. {
  380. return(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
  381. }
  382. /**
  383. * @}
  384. */
  385. /** @defgroup HAL_Exported_Functions_Group3 HAL Debug functions
  386. * @brief HAL Debug functions
  387. *
  388. @verbatim
  389. ===============================================================================
  390. ##### HAL Debug functions #####
  391. ===============================================================================
  392. [..] This section provides functions allowing to:
  393. (+) Enable/Disable Debug module during SLEEP mode
  394. (+) Enable/Disable Debug module during STOP0/STOP1/STOP2 modes
  395. (+) Enable/Disable Debug module during STANDBY mode
  396. @endverbatim
  397. * @{
  398. */
  399. /**
  400. * @brief Enable the Debug Module during SLEEP mode.
  401. * @retval None
  402. */
  403. void HAL_DBGMCU_EnableDBGSleepMode(void)
  404. {
  405. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
  406. }
  407. /**
  408. * @brief Disable the Debug Module during SLEEP mode.
  409. * @retval None
  410. */
  411. void HAL_DBGMCU_DisableDBGSleepMode(void)
  412. {
  413. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEP);
  414. }
  415. /**
  416. * @brief Enable the Debug Module during STOP0/STOP1/STOP2 modes.
  417. * @retval None
  418. */
  419. void HAL_DBGMCU_EnableDBGStopMode(void)
  420. {
  421. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
  422. }
  423. /**
  424. * @brief Disable the Debug Module during STOP0/STOP1/STOP2 modes.
  425. * @retval None
  426. */
  427. void HAL_DBGMCU_DisableDBGStopMode(void)
  428. {
  429. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
  430. }
  431. /**
  432. * @brief Enable the Debug Module during STANDBY mode.
  433. * @retval None
  434. */
  435. void HAL_DBGMCU_EnableDBGStandbyMode(void)
  436. {
  437. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
  438. }
  439. /**
  440. * @brief Disable the Debug Module during STANDBY mode.
  441. * @retval None
  442. */
  443. void HAL_DBGMCU_DisableDBGStandbyMode(void)
  444. {
  445. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBY);
  446. }
  447. /**
  448. * @}
  449. */
  450. /** @defgroup HAL_Exported_Functions_Group4 HAL SYSCFG configuration functions
  451. * @brief HAL SYSCFG configuration functions
  452. *
  453. @verbatim
  454. ===============================================================================
  455. ##### HAL SYSCFG configuration functions #####
  456. ===============================================================================
  457. [..] This section provides functions allowing to:
  458. (+) Start a hardware SRAM2 erase operation
  459. (+) Enable/Disable the Internal FLASH Bank Swapping
  460. (+) Configure the Voltage reference buffer
  461. (+) Enable/Disable the Voltage reference buffer
  462. (+) Enable/Disable the I/O analog switch voltage booster
  463. @endverbatim
  464. * @{
  465. */
  466. /**
  467. * @brief Start a hardware SRAM2 erase operation.
  468. * @note As long as SRAM2 is not erased the SRAM2ER bit will be set.
  469. * This bit is automatically reset at the end of the SRAM2 erase operation.
  470. * @retval None
  471. */
  472. void HAL_SYSCFG_SRAM2Erase(void)
  473. {
  474. /* unlock the write protection of the SRAM2ER bit */
  475. SYSCFG->SKR = 0xCA;
  476. SYSCFG->SKR = 0x53;
  477. /* Starts a hardware SRAM2 erase operation*/
  478. *(__IO uint32_t *) SCSR_SRAM2ER_BB = (uint8_t)0x00000001;
  479. }
  480. /**
  481. * @brief Enable the Internal FLASH Bank Swapping.
  482. *
  483. * @note This function can be used only for STM32L4xx devices.
  484. *
  485. * @note Flash Bank2 mapped at 0x08000000 (and aliased @0x00000000)
  486. * and Flash Bank1 mapped at 0x08100000 (and aliased at 0x00100000)
  487. *
  488. * @retval None
  489. */
  490. void HAL_SYSCFG_EnableMemorySwappingBank(void)
  491. {
  492. *(__IO uint32_t *)FB_MODE_BB = (uint32_t)ENABLE;
  493. }
  494. /**
  495. * @brief Disable the Internal FLASH Bank Swapping.
  496. *
  497. * @note This function can be used only for STM32L4xx devices.
  498. *
  499. * @note The default state : Flash Bank1 mapped at 0x08000000 (and aliased @0x0000 0000)
  500. * and Flash Bank2 mapped at 0x08100000 (and aliased at 0x00100000)
  501. *
  502. * @retval None
  503. */
  504. void HAL_SYSCFG_DisableMemorySwappingBank(void)
  505. {
  506. *(__IO uint32_t *)FB_MODE_BB = (uint32_t)DISABLE;
  507. }
  508. #if defined(VREFBUF)
  509. /**
  510. * @brief Configure the internal voltage reference buffer voltage scale.
  511. * @param VoltageScaling specifies the output voltage to achieve
  512. * This parameter can be one of the following values:
  513. * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE0: VREF_OUT1 around 2.048 V.
  514. * This requires VDDA equal to or higher than 2.4 V.
  515. * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE1: VREF_OUT2 around 2.5 V.
  516. * This requires VDDA equal to or higher than 2.8 V.
  517. * @retval None
  518. */
  519. void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)
  520. {
  521. /* Check the parameters */
  522. assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling));
  523. MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_VRS, VoltageScaling);
  524. }
  525. /**
  526. * @brief Configure the internal voltage reference buffer high impedance mode.
  527. * @param Mode specifies the high impedance mode
  528. * This parameter can be one of the following values:
  529. * @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE: VREF+ pin is internally connect to VREFINT output.
  530. * @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE: VREF+ pin is high impedance.
  531. * @retval None
  532. */
  533. void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)
  534. {
  535. /* Check the parameters */
  536. assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode));
  537. MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode);
  538. }
  539. /**
  540. * @brief Tune the Internal Voltage Reference buffer (VREFBUF).
  541. * @retval None
  542. */
  543. void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)
  544. {
  545. /* Check the parameters */
  546. assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
  547. MODIFY_REG(VREFBUF->CCR, VREFBUF_CCR_TRIM, TrimmingValue);
  548. }
  549. /**
  550. * @brief Enable the Internal Voltage Reference buffer (VREFBUF).
  551. * @retval HAL_OK/HAL_TIMEOUT
  552. */
  553. HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void)
  554. {
  555. uint32_t tickstart = 0;
  556. SET_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
  557. /* Get Start Tick*/
  558. tickstart = HAL_GetTick();
  559. /* Wait for VRR bit */
  560. while(READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == RESET)
  561. {
  562. if((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE)
  563. {
  564. return HAL_TIMEOUT;
  565. }
  566. }
  567. return HAL_OK;
  568. }
  569. /**
  570. * @brief Disable the Internal Voltage Reference buffer (VREFBUF).
  571. *
  572. * @retval None
  573. */
  574. void HAL_SYSCFG_DisableVREFBUF(void)
  575. {
  576. CLEAR_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
  577. }
  578. #endif /* VREFBUF */
  579. /**
  580. * @brief Enable the I/O analog switch voltage booster
  581. *
  582. * @retval None
  583. */
  584. void HAL_SYSCFG_EnableIOAnalogSwitchBooster(void)
  585. {
  586. SET_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_BOOSTEN);
  587. }
  588. /**
  589. * @brief Disable the I/O analog switch voltage booster
  590. *
  591. * @retval None
  592. */
  593. void HAL_SYSCFG_DisableIOAnalogSwitchBooster(void)
  594. {
  595. CLEAR_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_BOOSTEN);
  596. }
  597. /**
  598. * @}
  599. */
  600. /**
  601. * @}
  602. */
  603. #endif /* HAL_MODULE_ENABLED */
  604. /**
  605. * @}
  606. */
  607. /**
  608. * @}
  609. */
  610. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/