You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

855 lines
25 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32wbxx_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) 2019 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 "stm32wbxx_hal.h"
  35. /** @addtogroup STM32WBxx_HAL_Driver
  36. * @{
  37. */
  38. /** @addtogroup HAL
  39. * @brief HAL module driver
  40. * @{
  41. */
  42. #ifdef HAL_MODULE_ENABLED
  43. /* Private typedef -----------------------------------------------------------*/
  44. /* Private define ------------------------------------------------------------*/
  45. /** @defgroup HAL_Private_Constants HAL Private Constants
  46. * @{
  47. */
  48. /**
  49. * @brief STM32WBxx HAL Driver version number
  50. */
  51. #define __STM32WBxx_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */
  52. #define __STM32WBxx_HAL_VERSION_SUB1 (0x07U) /*!< [23:16] sub1 version */
  53. #define __STM32WBxx_HAL_VERSION_SUB2 (0x00U) /*!< [15:8] sub2 version */
  54. #define __STM32WBxx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
  55. #define __STM32WBxx_HAL_VERSION ((__STM32WBxx_HAL_VERSION_MAIN << 24U)\
  56. |(__STM32WBxx_HAL_VERSION_SUB1 << 16U)\
  57. |(__STM32WBxx_HAL_VERSION_SUB2 << 8U )\
  58. |(__STM32WBxx_HAL_VERSION_RC))
  59. #if defined(VREFBUF)
  60. #define VREFBUF_TIMEOUT_VALUE 10U /* 10 ms */
  61. #endif
  62. /**
  63. * @}
  64. */
  65. /* Private macro -------------------------------------------------------------*/
  66. /* Exported variables ---------------------------------------------------------*/
  67. /** @defgroup HAL_Exported_Variables HAL Exported Variables
  68. * @{
  69. */
  70. __IO uint32_t uwTick;
  71. uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
  72. HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */
  73. /**
  74. * @}
  75. */
  76. /* Private function prototypes -----------------------------------------------*/
  77. /* Exported functions --------------------------------------------------------*/
  78. /** @addtogroup HAL_Exported_Functions
  79. * @{
  80. */
  81. /** @addtogroup HAL_Exported_Functions_Group1
  82. * @brief HAL Initialization and Configuration functions
  83. *
  84. @verbatim
  85. ===============================================================================
  86. ##### HAL Initialization and Configuration functions #####
  87. ===============================================================================
  88. [..] This section provides functions allowing to:
  89. (+) Initialize the Flash interface the NVIC allocation and initial time base
  90. clock configuration.
  91. (+) De-initialize common part of the HAL.
  92. (+) Configure the time base source to have 1ms time base with a dedicated
  93. Tick interrupt priority.
  94. (++) SysTick timer is used by default as source of time base, but user
  95. can eventually implement his proper time base source (a general purpose
  96. timer for example or other time source), keeping in mind that Time base
  97. duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
  98. handled in milliseconds basis.
  99. (++) Time base configuration function (HAL_InitTick ()) is called automatically
  100. at the beginning of the program after reset by HAL_Init() or at any time
  101. when clock is configured, by HAL_RCC_ClockConfig().
  102. (++) Source of time base is configured to generate interrupts at regular
  103. time intervals. Care must be taken if HAL_Delay() is called from a
  104. peripheral ISR process, the Tick interrupt line must have higher priority
  105. (numerically lower) than the peripheral interrupt. Otherwise the caller
  106. ISR process will be blocked.
  107. (++) functions affecting time base configurations are declared as __weak
  108. to make override possible in case of other implementations in user file.
  109. @endverbatim
  110. * @{
  111. */
  112. /**
  113. * @brief This function is used to initialize the HAL Library; it must be the first
  114. * instruction to be executed in the main program (before to call any other
  115. * HAL function), it performs the following:
  116. * Configure the Flash prefetch, instruction and Data caches.
  117. * Configures the SysTick to generate an interrupt each 1 millisecond,
  118. * which is clocked by the MSI (at this stage, the clock is not yet
  119. * configured and thus the system is running from the internal MSI at 4 MHz).
  120. * Set NVIC Group Priority to 4.
  121. * Calls the HAL_MspInit() callback function defined in user file
  122. * "stm32wbxx_hal_msp.c" to do the global low level hardware initialization
  123. *
  124. * @note SysTick is used as time base for the HAL_Delay() function, the application
  125. * need to ensure that the SysTick time base is always set to 1 millisecond
  126. * to have correct HAL operation.
  127. * @retval HAL status
  128. */
  129. HAL_StatusTypeDef HAL_Init(void)
  130. {
  131. HAL_StatusTypeDef status = HAL_OK;
  132. /* Configure Flash prefetch, Instruction cache, Data cache */
  133. /* Default configuration at reset is: */
  134. /* - Prefetch disabled */
  135. /* - Instruction cache enabled */
  136. /* - Data cache enabled */
  137. #if (INSTRUCTION_CACHE_ENABLE == 0U)
  138. __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
  139. #endif /* INSTRUCTION_CACHE_ENABLE */
  140. #if (DATA_CACHE_ENABLE == 0U)
  141. __HAL_FLASH_DATA_CACHE_DISABLE();
  142. #endif /* DATA_CACHE_ENABLE */
  143. #if (PREFETCH_ENABLE != 0U)
  144. __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
  145. #endif /* PREFETCH_ENABLE */
  146. /* Set Interrupt Group Priority */
  147. HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
  148. /* Use SysTick as time base source and configure 1ms tick (default clock after Reset is MSI) */
  149. if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
  150. {
  151. status = HAL_ERROR;
  152. }
  153. else
  154. {
  155. /* Init the low level hardware */
  156. HAL_MspInit();
  157. }
  158. /* Return function status */
  159. return status;
  160. }
  161. /**
  162. * @brief This function de-Initializes common part of the HAL and stops the source of time base.
  163. * @note This function is optional.
  164. * @retval HAL status
  165. */
  166. HAL_StatusTypeDef HAL_DeInit(void)
  167. {
  168. /* Reset of all peripherals */
  169. __HAL_RCC_APB1_FORCE_RESET();
  170. __HAL_RCC_APB1_RELEASE_RESET();
  171. __HAL_RCC_APB2_FORCE_RESET();
  172. __HAL_RCC_APB2_RELEASE_RESET();
  173. __HAL_RCC_APB3_FORCE_RESET();
  174. __HAL_RCC_APB3_RELEASE_RESET();
  175. __HAL_RCC_AHB1_FORCE_RESET();
  176. __HAL_RCC_AHB1_RELEASE_RESET();
  177. __HAL_RCC_AHB2_FORCE_RESET();
  178. __HAL_RCC_AHB2_RELEASE_RESET();
  179. __HAL_RCC_AHB3_FORCE_RESET();
  180. __HAL_RCC_AHB3_RELEASE_RESET();
  181. /* De-Init the low level hardware */
  182. HAL_MspDeInit();
  183. /* Return function status */
  184. return HAL_OK;
  185. }
  186. /**
  187. * @brief Initialize the MSP.
  188. * @retval None
  189. */
  190. __weak void HAL_MspInit(void)
  191. {
  192. /* NOTE : This function should not be modified, when the callback is needed,
  193. the HAL_MspInit could be implemented in the user file
  194. */
  195. }
  196. /**
  197. * @brief DeInitializes the MSP.
  198. * @retval None
  199. */
  200. __weak void HAL_MspDeInit(void)
  201. {
  202. /* NOTE : This function should not be modified, when the callback is needed,
  203. the HAL_MspDeInit could be implemented in the user file
  204. */
  205. }
  206. /**
  207. * @brief This function configures the source of the time base:
  208. * The time source is configured to have 1ms time base with a dedicated
  209. * Tick interrupt priority.
  210. * @note This function is called automatically at the beginning of program after
  211. * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
  212. * @note In the default implementation, SysTick timer is the source of time base.
  213. * It is used to generate interrupts at regular time intervals.
  214. * Care must be taken if HAL_Delay() is called from a peripheral ISR process,
  215. * The SysTick interrupt must have higher priority (numerically lower)
  216. * than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
  217. * The function is declared as __weak to be overwritten in case of other
  218. * implementation in user file.
  219. * @param TickPriority Tick interrupt priority.
  220. * @retval HAL status
  221. */
  222. __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
  223. {
  224. HAL_StatusTypeDef status = HAL_OK;
  225. if ((uint32_t)uwTickFreq != 0U)
  226. {
  227. /*Configure the SysTick to have interrupt in 1ms time basis*/
  228. if (HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/ (1000U / (uint32_t)uwTickFreq)) == 0U)
  229. {
  230. /* Configure the SysTick IRQ priority */
  231. if (TickPriority < (1UL << __NVIC_PRIO_BITS))
  232. {
  233. HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
  234. uwTickPrio = TickPriority;
  235. }
  236. else
  237. {
  238. status = HAL_ERROR;
  239. }
  240. }
  241. else
  242. {
  243. status = HAL_ERROR;
  244. }
  245. }
  246. else
  247. {
  248. status = HAL_ERROR;
  249. }
  250. /* Return function status */
  251. return status;
  252. }
  253. /**
  254. * @}
  255. */
  256. /** @addtogroup HAL_Exported_Functions_Group2
  257. * @brief HAL Control functions
  258. *
  259. @verbatim
  260. ===============================================================================
  261. ##### HAL Control functions #####
  262. ===============================================================================
  263. [..] This section provides functions allowing to:
  264. (+) Provide a tick value in millisecond
  265. (+) Provide a blocking delay in millisecond
  266. (+) Suspend the time base source interrupt
  267. (+) Resume the time base source interrupt
  268. (+) Get the HAL API driver version
  269. (+) Get the device revision identifier
  270. (+) Get the device identifier
  271. (+) Get the unique device identifier
  272. @endverbatim
  273. * @{
  274. */
  275. /**
  276. * @brief This function is called to increment a global variable "uwTick"
  277. * used as application time base.
  278. * @note In the default implementation, this variable is incremented each 1ms
  279. * in SysTick ISR.
  280. * @note This function is declared as __weak to be overwritten in case of other
  281. * implementations in user file.
  282. * @retval None
  283. */
  284. __weak void HAL_IncTick(void)
  285. {
  286. uwTick += (uint32_t)uwTickFreq;
  287. }
  288. /**
  289. * @brief Provides a tick value in millisecond.
  290. * @note This function is declared as __weak to be overwritten in case of other
  291. * implementations in user file.
  292. * @retval tick value
  293. */
  294. __weak uint32_t HAL_GetTick(void)
  295. {
  296. return uwTick;
  297. }
  298. /**
  299. * @brief This function returns a tick priority.
  300. * @retval tick priority
  301. */
  302. uint32_t HAL_GetTickPrio(void)
  303. {
  304. return uwTickPrio;
  305. }
  306. /**
  307. * @brief Set new tick Freq.
  308. * @retval Status
  309. */
  310. HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
  311. {
  312. HAL_StatusTypeDef status = HAL_OK;
  313. HAL_TickFreqTypeDef prevTickFreq;
  314. assert_param(IS_TICKFREQ(Freq));
  315. if (uwTickFreq != Freq)
  316. {
  317. /* Back up uwTickFreq frequency */
  318. prevTickFreq = uwTickFreq;
  319. /* Update uwTickFreq global variable used by HAL_InitTick() */
  320. uwTickFreq = Freq;
  321. /* Apply the new tick Freq */
  322. status = HAL_InitTick(uwTickPrio);
  323. if (status != HAL_OK)
  324. {
  325. /* Restore previous tick frequency */
  326. uwTickFreq = prevTickFreq;
  327. }
  328. }
  329. return status;
  330. }
  331. /**
  332. * @brief Return tick frequency.
  333. * @retval tick period in Hz
  334. */
  335. HAL_TickFreqTypeDef HAL_GetTickFreq(void)
  336. {
  337. return uwTickFreq;
  338. }
  339. /**
  340. * @brief This function provides minimum delay (in milliseconds) based
  341. * on variable incremented.
  342. * @note In the default implementation , SysTick timer is the source of time base.
  343. * It is used to generate interrupts at regular time intervals where uwTick
  344. * is incremented.
  345. * @note This function is declared as __weak to be overwritten in case of other
  346. * implementations in user file.
  347. * @param Delay specifies the delay time length, in milliseconds.
  348. * @retval None
  349. */
  350. __weak void HAL_Delay(uint32_t Delay)
  351. {
  352. uint32_t tickstart = HAL_GetTick();
  353. uint32_t wait = Delay;
  354. /* Add a freq to guarantee minimum wait */
  355. if (wait < HAL_MAX_DELAY)
  356. {
  357. wait += (uint32_t)(uwTickFreq);
  358. }
  359. while ((HAL_GetTick() - tickstart) < wait)
  360. {
  361. }
  362. }
  363. /**
  364. * @brief Suspend Tick increment.
  365. * @note In the default implementation , SysTick timer is the source of time base. It is
  366. * used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
  367. * is called, the SysTick interrupt will be disabled and so Tick increment
  368. * is suspended.
  369. * @note This function is declared as __weak to be overwritten in case of other
  370. * implementations in user file.
  371. * @retval None
  372. */
  373. __weak void HAL_SuspendTick(void)
  374. {
  375. /* Disable SysTick Interrupt */
  376. CLEAR_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk);
  377. }
  378. /**
  379. * @brief Resume Tick increment.
  380. * @note In the default implementation , SysTick timer is the source of time base. It is
  381. * used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
  382. * is called, the SysTick interrupt will be enabled and so Tick increment
  383. * is resumed.
  384. * @note This function is declared as __weak to be overwritten in case of other
  385. * implementations in user file.
  386. * @retval None
  387. */
  388. __weak void HAL_ResumeTick(void)
  389. {
  390. /* Enable SysTick Interrupt */
  391. SET_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk);
  392. }
  393. /**
  394. * @brief Returns the HAL revision
  395. * @retval version : 0xXYZR (8bits for each decimal, R for RC)
  396. */
  397. uint32_t HAL_GetHalVersion(void)
  398. {
  399. return __STM32WBxx_HAL_VERSION;
  400. }
  401. /**
  402. * @brief Returns the device revision identifier.
  403. * @retval Device revision identifier
  404. */
  405. uint32_t HAL_GetREVID(void)
  406. {
  407. return(LL_DBGMCU_GetRevisionID());
  408. }
  409. /**
  410. * @brief Returns the device identifier.
  411. * @retval Device identifier
  412. */
  413. uint32_t HAL_GetDEVID(void)
  414. {
  415. return(LL_DBGMCU_GetDeviceID());
  416. }
  417. /**
  418. * @brief Return the first word of the unique device identifier (UID based on 96 bits)
  419. * @retval Device identifier
  420. */
  421. uint32_t HAL_GetUIDw0(void)
  422. {
  423. return(READ_REG(*((uint32_t *)UID_BASE)));
  424. }
  425. /**
  426. * @brief Return the second word of the unique device identifier (UID based on 96 bits)
  427. * @retval Device identifier
  428. */
  429. uint32_t HAL_GetUIDw1(void)
  430. {
  431. return(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
  432. }
  433. /**
  434. * @brief Return the third word of the unique device identifier (UID based on 96 bits)
  435. * @retval Device identifier
  436. */
  437. uint32_t HAL_GetUIDw2(void)
  438. {
  439. return(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
  440. }
  441. /**
  442. * @}
  443. */
  444. /** @addtogroup HAL_Exported_Functions_Group3
  445. * @brief HAL Debug functions
  446. *
  447. @verbatim
  448. ===============================================================================
  449. ##### HAL Debug functions #####
  450. ===============================================================================
  451. [..] This section provides functions allowing to:
  452. (+) Enable/Disable Debug module during SLEEP mode
  453. (+) Enable/Disable Debug module during STOP mode
  454. (+) Enable/Disable Debug module during STANDBY mode
  455. @endverbatim
  456. * @{
  457. */
  458. /**
  459. * @brief Enable the Debug Module during SLEEP mode
  460. * @retval None
  461. */
  462. void HAL_DBGMCU_EnableDBGSleepMode(void)
  463. {
  464. LL_DBGMCU_EnableDBGSleepMode();
  465. }
  466. /**
  467. * @brief Disable the Debug Module during SLEEP mode
  468. * @retval None
  469. */
  470. void HAL_DBGMCU_DisableDBGSleepMode(void)
  471. {
  472. LL_DBGMCU_DisableDBGSleepMode();
  473. }
  474. /**
  475. * @brief Enable the Debug Module during STOP mode
  476. * @retval None
  477. */
  478. void HAL_DBGMCU_EnableDBGStopMode(void)
  479. {
  480. LL_DBGMCU_EnableDBGStopMode();
  481. }
  482. /**
  483. * @brief Disable the Debug Module during STOP mode
  484. * @retval None
  485. */
  486. void HAL_DBGMCU_DisableDBGStopMode(void)
  487. {
  488. LL_DBGMCU_DisableDBGStopMode();
  489. }
  490. /**
  491. * @brief Enable the Debug Module during STANDBY mode
  492. * @retval None
  493. */
  494. void HAL_DBGMCU_EnableDBGStandbyMode(void)
  495. {
  496. LL_DBGMCU_EnableDBGStandbyMode();
  497. }
  498. /**
  499. * @brief Disable the Debug Module during STANDBY mode
  500. * @retval None
  501. */
  502. void HAL_DBGMCU_DisableDBGStandbyMode(void)
  503. {
  504. LL_DBGMCU_DisableDBGStandbyMode();
  505. }
  506. /**
  507. * @}
  508. */
  509. /** @defgroup HAL_Exported_Functions_Group4 HAL System Configuration functions
  510. * @brief HAL System Configuration functions
  511. *
  512. @verbatim
  513. ===============================================================================
  514. ##### HAL system configuration functions #####
  515. ===============================================================================
  516. [..] This section provides functions allowing to:
  517. (+) Start a hardware SRAM2 erase operation
  518. (+) Disable CPU2 SRAM fetch (execution)
  519. (+) Configure the Voltage reference buffer
  520. (+) Enable/Disable the Voltage reference buffer
  521. (+) Enable/Disable the I/O analog switch voltage booster
  522. (+) Enable/Disable the access for security IP (AES1, AES2, PKA, RNG)
  523. (+) Enable/Disable the access for security IP (AES2, PKA, RNG)
  524. @endverbatim
  525. * @{
  526. */
  527. /**
  528. * @brief Start a hardware SRAM2 erase operation.
  529. * @note As long as SRAM2 is not erased the SRAM2ER bit will be set.
  530. * This bit is automatically reset at the end of the SRAM2 erase operation.
  531. * @retval None
  532. */
  533. void HAL_SYSCFG_SRAM2Erase(void)
  534. {
  535. /* unlock the write protection of the SRAM2ER bit */
  536. __HAL_SYSCFG_SRAM2_WRP_UNLOCK();
  537. /* Starts a hardware SRAM2 erase operation*/
  538. __HAL_SYSCFG_SRAM2_ERASE();
  539. }
  540. /**
  541. * @brief Disable CPU2 SRAM fetch (execution) (This bit can be set by Firmware
  542. * and will only be reset by a Hardware reset, including a reset after Standby.)
  543. * @note Firmware writing 0 has no effect.
  544. * @retval None
  545. */
  546. void HAL_SYSCFG_DisableSRAMFetch(void)
  547. {
  548. LL_SYSCFG_DisableSRAMFetch();
  549. }
  550. /**
  551. * @brief Check if CPU2 SRAM fetch is enabled
  552. * @retval State of bit (1 or 0).
  553. */
  554. uint32_t HAL_SYSCFG_IsEnabledSRAMFetch(void)
  555. {
  556. return (LL_SYSCFG_IsEnabledSRAMFetch());
  557. }
  558. #if defined(VREFBUF)
  559. /**
  560. * @brief Configure the internal voltage reference buffer voltage scale.
  561. * @param VoltageScaling specifies the output voltage to achieve
  562. * This parameter can be one of the following values:
  563. * @arg @ref SYSCFG_VREFBUF_VOLTAGE_SCALE0 : VREF_OUT1 around 2.048 V.
  564. * This requires VDDA equal to or higher than 2.4 V.
  565. * @arg @ref SYSCFG_VREFBUF_VOLTAGE_SCALE1 : VREF_OUT1 around 2.5 V.
  566. * This requires VDDA equal to or higher than 2.8 V.
  567. * @note Retrieve the TrimmingValue from factory located at
  568. * VREFBUF_SC0_CAL_ADDR or VREFBUF_SC1_CAL_ADDR addresses.
  569. * @retval None
  570. */
  571. void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)
  572. {
  573. uint32_t TrimmingValue;
  574. /* Check the parameters */
  575. assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling));
  576. LL_VREFBUF_SetVoltageScaling(VoltageScaling);
  577. /* Restrieve Calibration data and store them into trimming field */
  578. if (VoltageScaling == SYSCFG_VREFBUF_VOLTAGE_SCALE0)
  579. {
  580. TrimmingValue = ((uint32_t) *VREFBUF_SC0_CAL_ADDR) & 0x3FU;
  581. }
  582. else
  583. {
  584. TrimmingValue = ((uint32_t) *VREFBUF_SC1_CAL_ADDR) & 0x3FU;
  585. }
  586. assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
  587. HAL_SYSCFG_VREFBUF_TrimmingConfig(TrimmingValue);
  588. }
  589. /**
  590. * @brief Configure the internal voltage reference buffer high impedance mode.
  591. * @param Mode specifies the high impedance mode
  592. * This parameter can be one of the following values:
  593. * @arg @ref SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE : VREF+ pin is internally connect to VREFINT output.
  594. * @arg @ref SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE : VREF+ pin is high impedance.
  595. * @retval HAL_OK/HAL_TIMEOUT
  596. */
  597. void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)
  598. {
  599. /* Check the parameters */
  600. assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode));
  601. MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode);
  602. }
  603. /**
  604. * @brief Tune the Internal Voltage Reference buffer (VREFBUF).
  605. * @note Each VrefBuf voltage scale is calibrated in production for each device,
  606. * data stored in flash memory.
  607. * Function @ref HAL_SYSCFG_VREFBUF_VoltageScalingConfig retrieves and
  608. * applies this calibration data as trimming value at each scale change.
  609. * Therefore, optionally, function @ref HAL_SYSCFG_VREFBUF_TrimmingConfig
  610. * can be used in a second time to fine tune the trimming.
  611. * @param TrimmingValue specifies trimming code for VREFBUF calibration
  612. * This parameter can be a number between Min_Data = 0x00 and Max_Data = 0x3F
  613. * @retval None
  614. */
  615. void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)
  616. {
  617. /* Check the parameters */
  618. assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
  619. LL_VREFBUF_SetTrimming(TrimmingValue);
  620. }
  621. /**
  622. * @brief Enable the Internal Voltage Reference buffer (VREFBUF).
  623. * @retval HAL_OK/HAL_TIMEOUT
  624. */
  625. HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void)
  626. {
  627. uint32_t tickstart;
  628. LL_VREFBUF_Enable();
  629. /* Get Start Tick*/
  630. tickstart = HAL_GetTick();
  631. /* Wait for VRR bit */
  632. while(READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == 0U)
  633. {
  634. if((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE)
  635. {
  636. return HAL_TIMEOUT;
  637. }
  638. }
  639. return HAL_OK;
  640. }
  641. /**
  642. * @brief Disable the Internal Voltage Reference buffer (VREFBUF).
  643. *
  644. * @retval None
  645. */
  646. void HAL_SYSCFG_DisableVREFBUF(void)
  647. {
  648. LL_VREFBUF_Disable();
  649. }
  650. #endif /* VREFBUF */
  651. /**
  652. * @brief Enable the I/O analog switch voltage booster
  653. *
  654. * @retval None
  655. */
  656. void HAL_SYSCFG_EnableIOBooster(void)
  657. {
  658. LL_SYSCFG_EnableAnalogBooster();
  659. }
  660. /**
  661. * @brief Disable the I/O analog switch voltage booster
  662. *
  663. * @retval None
  664. */
  665. void HAL_SYSCFG_DisableIOBooster(void)
  666. {
  667. LL_SYSCFG_DisableAnalogBooster();
  668. }
  669. #if defined(SYSCFG_CFGR1_ANASWVDD)
  670. /**
  671. * @brief Enable the I/O analog switch supplied by VDD
  672. * @note To be used when I/O analog switch voltage booster is not enabled
  673. * @retval None
  674. */
  675. void HAL_SYSCFG_EnableIOVdd(void)
  676. {
  677. LL_SYSCFG_EnableAnalogGpioSwitch();
  678. }
  679. /**
  680. * @brief Disable the I/O analog switch supplied by VDD
  681. *
  682. * @retval None
  683. */
  684. void HAL_SYSCFG_DisableIOVdd(void)
  685. {
  686. LL_SYSCFG_DisableAnalogGpioSwitch();
  687. }
  688. #endif /* SYSCFG_CFGR1_ANASWVDD */
  689. /**
  690. * @brief Enable the access for security IP
  691. * @note When the system is secure (ESE = 1), this register provides write access security and can
  692. * only be written by the CPU2. A write access from the CPU1 will be ignored and a bus error
  693. * is generated.
  694. * @param SecurityAccess This parameter can be a combination of the following values:
  695. * @arg @ref HAL_SYSCFG_SECURE_ACCESS_AES1
  696. * @arg @ref HAL_SYSCFG_SECURE_ACCESS_AES2
  697. * @arg @ref HAL_SYSCFG_SECURE_ACCESS_PKA
  698. * @arg @ref HAL_SYSCFG_SECURE_ACCESS_RNG
  699. * @retval None
  700. */
  701. void HAL_SYSCFG_EnableSecurityAccess(uint32_t SecurityAccess)
  702. {
  703. /* Check the parameters */
  704. assert_param(IS_SYSCFG_SECURITY_ACCESS(SecurityAccess));
  705. LL_SYSCFG_EnableSecurityAccess(SecurityAccess);
  706. }
  707. /**
  708. * @brief Disable the access for security IP
  709. * @note When the system is secure (ESE = 1), this register provides write access security and can
  710. * only be written by the CPU2. A write access from the CPU1 will be ignored and a bus error
  711. * is generated.
  712. * @param SecurityAccess This parameter can be a combination of the following values:
  713. * @arg @ref HAL_SYSCFG_SECURE_ACCESS_AES1
  714. * @arg @ref HAL_SYSCFG_SECURE_ACCESS_AES2
  715. * @arg @ref HAL_SYSCFG_SECURE_ACCESS_PKA
  716. * @arg @ref HAL_SYSCFG_SECURE_ACCESS_RNG
  717. * @retval None
  718. */
  719. void HAL_SYSCFG_DisableSecurityAccess(uint32_t SecurityAccess)
  720. {
  721. /* Check the parameters */
  722. assert_param(IS_SYSCFG_SECURITY_ACCESS(SecurityAccess));
  723. LL_SYSCFG_DisableSecurityAccess(SecurityAccess);
  724. }
  725. /**
  726. * @brief Indicate if access for security IP is enabled
  727. * @param SecurityAccess This parameter can be one of the following values:
  728. * @arg @ref HAL_SYSCFG_SECURE_ACCESS_AES1
  729. * @arg @ref HAL_SYSCFG_SECURE_ACCESS_AES2
  730. * @arg @ref HAL_SYSCFG_SECURE_ACCESS_PKA
  731. * @arg @ref HAL_SYSCFG_SECURE_ACCESS_RNG
  732. * @retval State of bit (1 or 0).
  733. */
  734. uint32_t HAL_SYSCFG_IsEnabledSecurityAccess(uint32_t SecurityAccess)
  735. {
  736. return (LL_SYSCFG_IsEnabledSecurityAccess(SecurityAccess));
  737. }
  738. /**
  739. * @}
  740. */
  741. /**
  742. * @}
  743. */
  744. #endif /* HAL_MODULE_ENABLED */
  745. /**
  746. * @}
  747. */
  748. /**
  749. * @}
  750. */
  751. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/