stm32wbxx_hal.c 25 KB

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