stm32g0xx_hal.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_hal.c
  4. * @author MCD Application Team
  5. * @brief HAL module driver.
  6. * This is the common part of the HAL initialization
  7. *
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * Copyright (c) 2018 STMicroelectronics.
  12. * All rights reserved.
  13. *
  14. * This software is licensed under terms that can be found in the LICENSE file
  15. * in the root directory of this software component.
  16. * If no LICENSE file comes with this software, it is provided AS-IS.
  17. *
  18. ******************************************************************************
  19. @verbatim
  20. ==============================================================================
  21. ##### How to use this driver #####
  22. ==============================================================================
  23. [..]
  24. The common HAL driver contains a set of generic and common APIs that can be
  25. used by the PPP peripheral drivers and the user to start using the HAL.
  26. [..]
  27. The HAL contains two APIs categories:
  28. (+) Common HAL APIs
  29. (+) Services HAL APIs
  30. @endverbatim
  31. ******************************************************************************
  32. */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "stm32g0xx_hal.h"
  35. /** @addtogroup STM32G0xx_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 STM32G0xx HAL Driver version number
  50. */
  51. #define __STM32G0xx_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */
  52. #define __STM32G0xx_HAL_VERSION_SUB1 (0x04U) /*!< [23:16] sub1 version */
  53. #define __STM32G0xx_HAL_VERSION_SUB2 (0x06U) /*!< [15:8] sub2 version */
  54. #define __STM32G0xx_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
  55. #define __STM32G0xx_HAL_VERSION ((__STM32G0xx_HAL_VERSION_MAIN << 24U)\
  56. |(__STM32G0xx_HAL_VERSION_SUB1 << 16U)\
  57. |(__STM32G0xx_HAL_VERSION_SUB2 << 8U )\
  58. |(__STM32G0xx_HAL_VERSION_RC))
  59. #if defined(VREFBUF)
  60. #define VREFBUF_TIMEOUT_VALUE 10U /*!< 10 ms */
  61. #endif /* VREFBUF */
  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 Configure the Flash prefetch and the Instruction cache,
  114. * the time base source, NVIC and any required global low level hardware
  115. * by calling the HAL_MspInit() callback function to be optionally defined in user file
  116. * stm32g0xx_hal_msp.c.
  117. *
  118. * @note HAL_Init() function is called at the beginning of program after reset and before
  119. * the clock configuration.
  120. *
  121. * @note In the default implementation the System Timer (Systick) is used as source of time base.
  122. * The Systick configuration is based on HSI clock, as HSI is the clock
  123. * used after a system Reset.
  124. * Once done, time base tick starts incrementing: the tick variable counter is incremented
  125. * each 1ms in the SysTick_Handler() interrupt handler.
  126. *
  127. * @retval HAL status
  128. */
  129. HAL_StatusTypeDef HAL_Init(void)
  130. {
  131. HAL_StatusTypeDef status = HAL_OK;
  132. /* Configure Flash prefetch, Instruction cache */
  133. /* Default configuration at reset is: */
  134. /* - Prefetch disabled */
  135. /* - Instruction cache enabled */
  136. #if (INSTRUCTION_CACHE_ENABLE == 0U)
  137. __HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
  138. #endif /* INSTRUCTION_CACHE_ENABLE */
  139. #if (PREFETCH_ENABLE != 0U)
  140. __HAL_FLASH_PREFETCH_BUFFER_ENABLE();
  141. #endif /* PREFETCH_ENABLE */
  142. /* Use SysTick as time base source and configure 1ms tick (default clock after Reset is HSI) */
  143. if (HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
  144. {
  145. status = HAL_ERROR;
  146. }
  147. else
  148. {
  149. /* Init the low level hardware */
  150. HAL_MspInit();
  151. }
  152. /* Return function status */
  153. return status;
  154. }
  155. /**
  156. * @brief This function de-Initializes common part of the HAL and stops the source of time base.
  157. * @note This function is optional.
  158. * @retval HAL status
  159. */
  160. HAL_StatusTypeDef HAL_DeInit(void)
  161. {
  162. /* Reset of all peripherals */
  163. __HAL_RCC_APB1_FORCE_RESET();
  164. __HAL_RCC_APB1_RELEASE_RESET();
  165. __HAL_RCC_APB2_FORCE_RESET();
  166. __HAL_RCC_APB2_RELEASE_RESET();
  167. __HAL_RCC_AHB_FORCE_RESET();
  168. __HAL_RCC_AHB_RELEASE_RESET();
  169. __HAL_RCC_IOP_FORCE_RESET();
  170. __HAL_RCC_IOP_RELEASE_RESET();
  171. /* De-Init the low level hardware */
  172. HAL_MspDeInit();
  173. /* Return function status */
  174. return HAL_OK;
  175. }
  176. /**
  177. * @brief Initialize the MSP.
  178. * @retval None
  179. */
  180. __weak void HAL_MspInit(void)
  181. {
  182. /* NOTE : This function should not be modified, when the callback is needed,
  183. the HAL_MspInit could be implemented in the user file
  184. */
  185. }
  186. /**
  187. * @brief DeInitializes the MSP.
  188. * @retval None
  189. */
  190. __weak void HAL_MspDeInit(void)
  191. {
  192. /* NOTE : This function should not be modified, when the callback is needed,
  193. the HAL_MspDeInit could be implemented in the user file
  194. */
  195. }
  196. /**
  197. * @brief This function configures the source of the time base:
  198. * The time source is configured to have 1ms time base with a dedicated
  199. * Tick interrupt priority.
  200. * @note This function is called automatically at the beginning of program after
  201. * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
  202. * @note In the default implementation, SysTick timer is the source of time base.
  203. * It is used to generate interrupts at regular time intervals.
  204. * Care must be taken if HAL_Delay() is called from a peripheral ISR process,
  205. * The SysTick interrupt must have higher priority (numerically lower)
  206. * than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
  207. * The function is declared as __weak to be overwritten in case of other
  208. * implementation in user file.
  209. * @param TickPriority Tick interrupt priority.
  210. * @retval HAL status
  211. */
  212. __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
  213. {
  214. HAL_StatusTypeDef status = HAL_OK;
  215. /* Check uwTickFreq for MisraC 2012 (even if uwTickFreq is a enum type that doesn't take the value zero)*/
  216. if ((uint32_t)uwTickFreq != 0U)
  217. {
  218. /*Configure the SysTick to have interrupt in 1ms time basis*/
  219. if (HAL_SYSTICK_Config(SystemCoreClock / (1000U /(uint32_t)uwTickFreq)) == 0U)
  220. {
  221. /* Configure the SysTick IRQ priority */
  222. if (TickPriority < (1UL << __NVIC_PRIO_BITS))
  223. {
  224. HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
  225. uwTickPrio = TickPriority;
  226. }
  227. else
  228. {
  229. status = HAL_ERROR;
  230. }
  231. }
  232. else
  233. {
  234. status = HAL_ERROR;
  235. }
  236. }
  237. else
  238. {
  239. status = HAL_ERROR;
  240. }
  241. /* Return function status */
  242. return status;
  243. }
  244. /**
  245. * @}
  246. */
  247. /** @addtogroup HAL_Exported_Functions_Group2
  248. * @brief HAL Control functions
  249. *
  250. @verbatim
  251. ===============================================================================
  252. ##### HAL Control functions #####
  253. ===============================================================================
  254. [..] This section provides functions allowing to:
  255. (+) Provide a tick value in millisecond
  256. (+) Provide a blocking delay in millisecond
  257. (+) Suspend the time base source interrupt
  258. (+) Resume the time base source interrupt
  259. (+) Get the HAL API driver version
  260. (+) Get the device identifier
  261. (+) Get the device revision identifier
  262. @endverbatim
  263. * @{
  264. */
  265. /**
  266. * @brief This function is called to increment a global variable "uwTick"
  267. * used as application time base.
  268. * @note In the default implementation, this variable is incremented each 1ms
  269. * in SysTick ISR.
  270. * @note This function is declared as __weak to be overwritten in case of other
  271. * implementations in user file.
  272. * @retval None
  273. */
  274. __weak void HAL_IncTick(void)
  275. {
  276. uwTick += (uint32_t)uwTickFreq;
  277. }
  278. /**
  279. * @brief Provides a tick value in millisecond.
  280. * @note This function is declared as __weak to be overwritten in case of other
  281. * implementations in user file.
  282. * @retval tick value
  283. */
  284. __weak uint32_t HAL_GetTick(void)
  285. {
  286. return uwTick;
  287. }
  288. /**
  289. * @brief This function returns a tick priority.
  290. * @retval tick priority
  291. */
  292. uint32_t HAL_GetTickPrio(void)
  293. {
  294. return uwTickPrio;
  295. }
  296. /**
  297. * @brief Set new tick Freq.
  298. * @retval status
  299. */
  300. HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
  301. {
  302. HAL_StatusTypeDef status = HAL_OK;
  303. HAL_TickFreqTypeDef prevTickFreq;
  304. assert_param(IS_TICKFREQ(Freq));
  305. if (uwTickFreq != Freq)
  306. {
  307. /* Back up uwTickFreq frequency */
  308. prevTickFreq = uwTickFreq;
  309. /* Update uwTickFreq global variable used by HAL_InitTick() */
  310. uwTickFreq = Freq;
  311. /* Apply the new tick Freq */
  312. status = HAL_InitTick(uwTickPrio);
  313. if (status != HAL_OK)
  314. {
  315. /* Restore previous tick frequency */
  316. uwTickFreq = prevTickFreq;
  317. }
  318. }
  319. return status;
  320. }
  321. /**
  322. * @brief return tick frequency.
  323. * @retval Tick frequency.
  324. * Value of @ref HAL_TickFreqTypeDef.
  325. */
  326. HAL_TickFreqTypeDef HAL_GetTickFreq(void)
  327. {
  328. return uwTickFreq;
  329. }
  330. /**
  331. * @brief This function provides minimum delay (in milliseconds) based
  332. * on variable incremented.
  333. * @note In the default implementation , SysTick timer is the source of time base.
  334. * It is used to generate interrupts at regular time intervals where uwTick
  335. * is incremented.
  336. * @note This function is declared as __weak to be overwritten in case of other
  337. * implementations in user file.
  338. * @param Delay specifies the delay time length, in milliseconds.
  339. * @retval None
  340. */
  341. __weak void HAL_Delay(uint32_t Delay)
  342. {
  343. uint32_t tickstart = HAL_GetTick();
  344. uint32_t wait = Delay;
  345. /* Add a freq to guarantee minimum wait */
  346. if (wait < HAL_MAX_DELAY)
  347. {
  348. wait += (uint32_t)(uwTickFreq);
  349. }
  350. while ((HAL_GetTick() - tickstart) < wait)
  351. {
  352. }
  353. }
  354. /**
  355. * @brief Suspend Tick increment.
  356. * @note In the default implementation , SysTick timer is the source of time base. It is
  357. * used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
  358. * is called, the SysTick interrupt will be disabled and so Tick increment
  359. * is suspended.
  360. * @note This function is declared as __weak to be overwritten in case of other
  361. * implementations in user file.
  362. * @retval None
  363. */
  364. __weak void HAL_SuspendTick(void)
  365. {
  366. /* Disable SysTick Interrupt */
  367. CLEAR_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk);
  368. }
  369. /**
  370. * @brief Resume Tick increment.
  371. * @note In the default implementation , SysTick timer is the source of time base. It is
  372. * used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
  373. * is called, the SysTick interrupt will be enabled and so Tick increment
  374. * is resumed.
  375. * @note This function is declared as __weak to be overwritten in case of other
  376. * implementations in user file.
  377. * @retval None
  378. */
  379. __weak void HAL_ResumeTick(void)
  380. {
  381. /* Enable SysTick Interrupt */
  382. SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
  383. }
  384. /**
  385. * @brief Returns the HAL revision
  386. * @retval version : 0xXYZR (8bits for each decimal, R for RC)
  387. */
  388. uint32_t HAL_GetHalVersion(void)
  389. {
  390. return __STM32G0xx_HAL_VERSION;
  391. }
  392. /**
  393. * @brief Returns the device revision identifier.
  394. * @retval Device revision identifier
  395. */
  396. uint32_t HAL_GetREVID(void)
  397. {
  398. return ((DBG->IDCODE & DBG_IDCODE_REV_ID) >> 16U);
  399. }
  400. /**
  401. * @brief Returns the device identifier.
  402. * @retval Device identifier
  403. */
  404. uint32_t HAL_GetDEVID(void)
  405. {
  406. return ((DBG->IDCODE) & DBG_IDCODE_DEV_ID);
  407. }
  408. /**
  409. * @brief Returns first word of the unique device identifier (UID based on 96 bits)
  410. * @retval Device identifier
  411. */
  412. uint32_t HAL_GetUIDw0(void)
  413. {
  414. return (READ_REG(*((uint32_t *)UID_BASE)));
  415. }
  416. /**
  417. * @brief Returns second word of the unique device identifier (UID based on 96 bits)
  418. * @retval Device identifier
  419. */
  420. uint32_t HAL_GetUIDw1(void)
  421. {
  422. return (READ_REG(*((uint32_t *)(UID_BASE + 4U))));
  423. }
  424. /**
  425. * @brief Returns third word of the unique device identifier (UID based on 96 bits)
  426. * @retval Device identifier
  427. */
  428. uint32_t HAL_GetUIDw2(void)
  429. {
  430. return (READ_REG(*((uint32_t *)(UID_BASE + 8U))));
  431. }
  432. /**
  433. * @}
  434. */
  435. /** @addtogroup HAL_Exported_Functions_Group3
  436. * @brief HAL Debug functions
  437. *
  438. @verbatim
  439. ===============================================================================
  440. ##### HAL Debug functions #####
  441. ===============================================================================
  442. [..] This section provides functions allowing to:
  443. (+) Enable/Disable Debug module during STOP mode
  444. (+) Enable/Disable Debug module during STANDBY mode
  445. @endverbatim
  446. * @{
  447. */
  448. /**
  449. * @brief Enable the Debug Module during STOP mode
  450. * @retval None
  451. */
  452. void HAL_DBGMCU_EnableDBGStopMode(void)
  453. {
  454. SET_BIT(DBG->CR, DBG_CR_DBG_STOP);
  455. }
  456. /**
  457. * @brief Disable the Debug Module during STOP mode
  458. * @retval None
  459. */
  460. void HAL_DBGMCU_DisableDBGStopMode(void)
  461. {
  462. CLEAR_BIT(DBG->CR, DBG_CR_DBG_STOP);
  463. }
  464. /**
  465. * @brief Enable the Debug Module during STANDBY mode
  466. * @retval None
  467. */
  468. void HAL_DBGMCU_EnableDBGStandbyMode(void)
  469. {
  470. SET_BIT(DBG->CR, DBG_CR_DBG_STANDBY);
  471. }
  472. /**
  473. * @brief Disable the Debug Module during STANDBY mode
  474. * @retval None
  475. */
  476. void HAL_DBGMCU_DisableDBGStandbyMode(void)
  477. {
  478. CLEAR_BIT(DBG->CR, DBG_CR_DBG_STANDBY);
  479. }
  480. /**
  481. * @}
  482. */
  483. /** @addtogroup HAL_Exported_Functions_Group4
  484. * @brief SYSCFG configuration functions
  485. *
  486. @verbatim
  487. ===============================================================================
  488. ##### HAL SYSCFG configuration functions #####
  489. ===============================================================================
  490. [..] This section provides functions allowing to:
  491. (+) Enable/Disable Pin remap
  492. (+) Configure the Voltage reference buffer
  493. (+) Enable/Disable the Voltage reference buffer
  494. (+) Enable/Disable the I/O analog switch voltage booster
  495. (+) Enable/Disable dead battery behavior(*)
  496. (+) Configure Clamping Diode on specific pins(*)
  497. (*) Feature not available on all devices
  498. @endverbatim
  499. * @{
  500. */
  501. #if defined(VREFBUF)
  502. /**
  503. * @brief Configure the internal voltage reference buffer voltage scale.
  504. * @param VoltageScaling specifies the output voltage to achieve
  505. * This parameter can be one of the following values:
  506. * @arg @ref SYSCFG_VREFBUF_VoltageScale
  507. * @retval None
  508. */
  509. void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)
  510. {
  511. /* Check the parameters */
  512. assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling));
  513. MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_VRS, VoltageScaling);
  514. }
  515. /**
  516. * @brief Configure the internal voltage reference buffer high impedance mode.
  517. * @param Mode specifies the high impedance mode
  518. * This parameter can be one of the following values:
  519. * @arg @ref SYSCFG_VREFBUF_HighImpedance
  520. * @retval None
  521. */
  522. void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)
  523. {
  524. /* Check the parameters */
  525. assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode));
  526. MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode);
  527. }
  528. /**
  529. * @brief Tune the Internal Voltage Reference buffer (VREFBUF).
  530. * @note VrefBuf voltage scale is calibrated in production for each device,
  531. * using voltage scale 1. This calibration value is loaded
  532. * as default trimming value at device power up.
  533. * This trimming value can be fine tuned for voltage scales 0 and 1
  534. * using this function.
  535. * @retval None
  536. */
  537. void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)
  538. {
  539. /* Check the parameters */
  540. assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
  541. MODIFY_REG(VREFBUF->CCR, VREFBUF_CCR_TRIM, TrimmingValue);
  542. }
  543. /**
  544. * @brief Enable the Internal Voltage Reference buffer (VREFBUF).
  545. * @retval HAL_OK/HAL_TIMEOUT
  546. */
  547. HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void)
  548. {
  549. uint32_t tickstart;
  550. SET_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
  551. /* Get Start Tick*/
  552. tickstart = HAL_GetTick();
  553. /* Wait for VRR bit */
  554. while (READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == 0x00U)
  555. {
  556. if ((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE)
  557. {
  558. return HAL_TIMEOUT;
  559. }
  560. }
  561. return HAL_OK;
  562. }
  563. /**
  564. * @brief Disable the Internal Voltage Reference buffer (VREFBUF).
  565. *
  566. * @retval None
  567. */
  568. void HAL_SYSCFG_DisableVREFBUF(void)
  569. {
  570. CLEAR_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
  571. }
  572. #endif /* VREFBUF */
  573. /**
  574. * @brief Enable the I/O analog switch voltage booster
  575. * @retval None
  576. */
  577. void HAL_SYSCFG_EnableIOAnalogSwitchBooster(void)
  578. {
  579. SET_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_BOOSTEN);
  580. }
  581. /**
  582. * @brief Disable the I/O analog switch voltage booster
  583. * @retval None
  584. */
  585. void HAL_SYSCFG_DisableIOAnalogSwitchBooster(void)
  586. {
  587. CLEAR_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_BOOSTEN);
  588. }
  589. /**
  590. * @brief Enable the remap on PA11_PA12
  591. * @param PinRemap specifies which pins have to be remapped
  592. * This parameter can be any combination of the following values:
  593. * @arg @ref SYSCFG_REMAP_PA11
  594. * @arg @ref SYSCFG_REMAP_PA12
  595. * @retval None
  596. */
  597. void HAL_SYSCFG_EnableRemap(uint32_t PinRemap)
  598. {
  599. /* Check the parameter */
  600. assert_param(IS_HAL_REMAP_PIN(PinRemap));
  601. SET_BIT(SYSCFG->CFGR1, PinRemap);
  602. }
  603. /**
  604. * @brief Disable the remap on PA11_PA12
  605. * @param PinRemap specifies which pins will behave normally
  606. * This parameter can be any combination of the following values:
  607. * @arg @ref SYSCFG_REMAP_PA11
  608. * @arg @ref SYSCFG_REMAP_PA12
  609. * @retval None
  610. */
  611. void HAL_SYSCFG_DisableRemap(uint32_t PinRemap)
  612. {
  613. /* Check the parameter */
  614. assert_param(IS_HAL_REMAP_PIN(PinRemap));
  615. CLEAR_BIT(SYSCFG->CFGR1, PinRemap);
  616. }
  617. #if defined(SYSCFG_CDEN_SUPPORT)
  618. /**
  619. * @brief Enable Clamping Diode on specified IO
  620. * @param PinConfig specifies on which pins clamping Diode has to be enabled
  621. * This parameter can be any combination of the following values:
  622. * @arg @ref SYSCFG_ClampingDiode
  623. * @retval None
  624. */
  625. void HAL_SYSCFG_EnableClampingDiode(uint32_t PinConfig)
  626. {
  627. /* Check the parameter */
  628. assert_param(IS_SYSCFG_CLAMPINGDIODE(PinConfig));
  629. SET_BIT(SYSCFG->CFGR2, PinConfig);
  630. }
  631. /**
  632. * @brief Disable Clamping Diode on specified IO
  633. * @param PinConfig specifies on which pins clamping Diode has to be disabled
  634. * This parameter can be any combination of the following values:
  635. * @arg @ref SYSCFG_ClampingDiode
  636. * @retval None
  637. */
  638. void HAL_SYSCFG_DisableClampingDiode(uint32_t PinConfig)
  639. {
  640. /* Check the parameter */
  641. assert_param(IS_SYSCFG_CLAMPINGDIODE(PinConfig));
  642. CLEAR_BIT(SYSCFG->CFGR2, PinConfig);
  643. }
  644. #endif /* SYSCFG_CDEN_SUPPORT */
  645. #if defined (SYSCFG_CFGR1_UCPD1_STROBE) || defined (SYSCFG_CFGR1_UCPD2_STROBE)
  646. /**
  647. * @brief Strobe configuration of GPIO depending on UCPDx dead battery settings
  648. * @param ConfigDeadBattery specifies on which pins to make effective or not Dead Battery sw configuration
  649. * This parameter can be any combination of the following values:
  650. * @arg @ref SYSCFG_UCPD1_STROBE
  651. * @arg @ref SYSCFG_UCPD2_STROBE
  652. * @retval None
  653. */
  654. void HAL_SYSCFG_StrobeDBattpinsConfig(uint32_t ConfigDeadBattery)
  655. {
  656. assert_param(IS_SYSCFG_DBATT_CONFIG(ConfigDeadBattery));
  657. /* Change strobe configuration of GPIO depending on UCPDx dead battery settings */
  658. MODIFY_REG(SYSCFG->CFGR1, (SYSCFG_CFGR1_UCPD1_STROBE | SYSCFG_CFGR1_UCPD2_STROBE), ConfigDeadBattery);
  659. }
  660. #endif /* SYSCFG_CFGR1_UCPD1_STROBE || SYSCFG_CFGR1_UCPD2_STROBE */
  661. /**
  662. * @}
  663. */
  664. /**
  665. * @}
  666. */
  667. #endif /* HAL_MODULE_ENABLED */
  668. /**
  669. * @}
  670. */
  671. /**
  672. * @}
  673. */