py32f002b_hal.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /**
  2. ******************************************************************************
  3. * @file py32f002b_hal.c
  4. * @author MCU 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) 2023 Puya Semiconductor Co.
  24. * All rights reserved.</center></h2>
  25. *
  26. * This software component is licensed by Puya 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. * @attention
  33. *
  34. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  35. * All rights reserved.</center></h2>
  36. *
  37. * This software component is licensed by ST under BSD 3-Clause license,
  38. * the "License"; You may not use this file except in compliance with the
  39. * License. You may obtain a copy of the License at:
  40. * opensource.org/licenses/BSD-3-Clause
  41. *
  42. ******************************************************************************
  43. */
  44. /* Includes ------------------------------------------------------------------*/
  45. #include "py32f0xx_hal.h"
  46. /** @addtogroup PY32F002B_HAL_Driver
  47. * @{
  48. */
  49. /** @addtogroup HAL
  50. * @brief HAL module driver
  51. * @{
  52. */
  53. #ifdef HAL_MODULE_ENABLED
  54. /* Private typedef -----------------------------------------------------------*/
  55. /* Private define ------------------------------------------------------------*/
  56. /** @defgroup HAL_Private_Constants HAL Private Constants
  57. * @{
  58. */
  59. /**
  60. * @brief PY32F002B HAL Driver version number
  61. */
  62. #define __PY32F002B_HAL_VERSION_MAIN (0x01U) /*!< [31:24] main version */
  63. #define __PY32F002B_HAL_VERSION_SUB1 (0x00U) /*!< [23:16] sub1 version */
  64. #define __PY32F002B_HAL_VERSION_SUB2 (0x00U) /*!< [15:8] sub2 version */
  65. #define __PY32F002B_HAL_VERSION_RC (0x00U) /*!< [7:0] release candidate */
  66. #define __PY32F002B_HAL_VERSION ((__PY32F002B_HAL_VERSION_MAIN << 24U)\
  67. |(__PY32F002B_HAL_VERSION_SUB1 << 16U)\
  68. |(__PY32F002B_HAL_VERSION_SUB2 << 8U )\
  69. |(__PY32F002B_HAL_VERSION_RC))
  70. #if defined(VREFBUF)
  71. #define VREFBUF_TIMEOUT_VALUE 10U /*!< 10 ms */
  72. #endif /* VREFBUF */
  73. /**
  74. * @}
  75. */
  76. /* Private macro -------------------------------------------------------------*/
  77. /* Exported variables --------------------------------------------------------*/
  78. /** @defgroup HAL_Exported_Variables HAL Exported Variables
  79. * @{
  80. */
  81. __IO uint32_t uwTick;
  82. uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
  83. uint32_t uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */
  84. /**
  85. * @}
  86. */
  87. /* Private function prototypes -----------------------------------------------*/
  88. /* Exported functions --------------------------------------------------------*/
  89. /** @addtogroup HAL_Exported_Functions
  90. * @{
  91. */
  92. /** @addtogroup HAL_Exported_Functions_Group1 HAL Initialization and Configuration functions
  93. * @brief HAL Initialization and Configuration functions
  94. *
  95. @verbatim
  96. ===============================================================================
  97. ##### HAL Initialization and Configuration functions #####
  98. ===============================================================================
  99. [..] This section provides functions allowing to:
  100. (+) Initialize the Flash interface the NVIC allocation and initial time base
  101. clock configuration.
  102. (+) De-initialize common part of the HAL.
  103. (+) Configure the time base source to have 1ms time base with a dedicated
  104. Tick interrupt priority.
  105. (++) SysTick timer is used by default as source of time base, but user
  106. can eventually implement his proper time base source (a general purpose
  107. timer for example or other time source), keeping in mind that Time base
  108. duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
  109. handled in milliseconds basis.
  110. (++) Time base configuration function (HAL_InitTick ()) is called automatically
  111. at the beginning of the program after reset by HAL_Init() or at any time
  112. when clock is configured, by HAL_RCC_ClockConfig().
  113. (++) Source of time base is configured to generate interrupts at regular
  114. time intervals. Care must be taken if HAL_Delay() is called from a
  115. peripheral ISR process, the Tick interrupt line must have higher priority
  116. (numerically lower) than the peripheral interrupt. Otherwise the caller
  117. ISR process will be blocked.
  118. (++) functions affecting time base configurations are declared as __weak
  119. to make override possible in case of other implementations in user file.
  120. @endverbatim
  121. * @{
  122. */
  123. /**
  124. * @brief Configure the Flash prefetch and the Instruction cache,
  125. * the time base source, NVIC and any required global low level hardware
  126. * by calling the HAL_MspInit() callback function to be optionally defined in user file
  127. * PY32F002B_hal_msp.c.
  128. *
  129. * @note HAL_Init() function is called at the beginning of program after reset and before
  130. * the clock configuration.
  131. *
  132. * @note In the default implementation the System Timer (Systick) is used as source of time base.
  133. * The Systick configuration is based on HSI clock, as HSI is the clock
  134. * used after a system Reset.
  135. * Once done, time base tick starts incrementing: the tick variable counter is incremented
  136. * each 1ms in the SysTick_Handler() interrupt handler.
  137. *
  138. * @retval HAL status
  139. */
  140. HAL_StatusTypeDef HAL_Init(void)
  141. {
  142. HAL_StatusTypeDef status = HAL_OK;
  143. /* Configure Flash prefetch, Instruction cache */
  144. /* Default configuration at reset is: */
  145. /* - Prefetch disabled */
  146. /* - Instruction cache enabled */
  147. /* Use SysTick as time base source and configure 1ms tick (default clock after Reset is HSI) */
  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_AHB_FORCE_RESET();
  173. __HAL_RCC_AHB_RELEASE_RESET();
  174. __HAL_RCC_IOP_FORCE_RESET();
  175. __HAL_RCC_IOP_RELEASE_RESET();
  176. /* De-Init the low level hardware */
  177. HAL_MspDeInit();
  178. /* Return function status */
  179. return HAL_OK;
  180. }
  181. /**
  182. * @brief Initialize the MSP.
  183. * @retval None
  184. */
  185. __weak void HAL_MspInit(void)
  186. {
  187. /* NOTE : This function should not be modified, when the callback is needed,
  188. the HAL_MspInit could be implemented in the user file
  189. */
  190. }
  191. /**
  192. * @brief DeInitializes the MSP.
  193. * @retval None
  194. */
  195. __weak void HAL_MspDeInit(void)
  196. {
  197. /* NOTE : This function should not be modified, when the callback is needed,
  198. the HAL_MspDeInit could be implemented in the user file
  199. */
  200. }
  201. /**
  202. * @brief This function configures the source of the time base:
  203. * The time source is configured to have 1ms time base with a dedicated
  204. * Tick interrupt priority.
  205. * @note This function is called automatically at the beginning of program after
  206. * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
  207. * @note In the default implementation, SysTick timer is the source of time base.
  208. * It is used to generate interrupts at regular time intervals.
  209. * Care must be taken if HAL_Delay() is called from a peripheral ISR process,
  210. * The SysTick interrupt must have higher priority (numerically lower)
  211. * than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
  212. * The function is declared as __weak to be overwritten in case of other
  213. * implementation in user file.
  214. * @param TickPriority Tick interrupt priority.
  215. * @retval HAL status
  216. */
  217. __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
  218. {
  219. HAL_StatusTypeDef status = HAL_OK;
  220. if (uwTickFreq != 0U)
  221. {
  222. /*Configure the SysTick to have interrupt in 1ms time basis*/
  223. if (HAL_SYSTICK_Config(SystemCoreClock / (1000U /uwTickFreq)) == 0U)
  224. {
  225. /* Configure the SysTick IRQ priority */
  226. if (TickPriority < (1UL << __NVIC_PRIO_BITS))
  227. {
  228. HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
  229. uwTickPrio = TickPriority;
  230. }
  231. else
  232. {
  233. status = HAL_ERROR;
  234. }
  235. }
  236. else
  237. {
  238. status = HAL_ERROR;
  239. }
  240. }
  241. else
  242. {
  243. status = HAL_ERROR;
  244. }
  245. /* Return function status */
  246. return status;
  247. }
  248. /**
  249. * @}
  250. */
  251. /** @addtogroup HAL_Exported_Functions_Group2 HAL Control functions
  252. * @brief HAL Control functions
  253. *
  254. @verbatim
  255. ===============================================================================
  256. ##### HAL Control functions #####
  257. ===============================================================================
  258. [..] This section provides functions allowing to:
  259. (+) Provide a tick value in millisecond
  260. (+) Provide a blocking delay in millisecond
  261. (+) Suspend the time base source interrupt
  262. (+) Resume the time base source interrupt
  263. (+) Get the HAL API driver version
  264. (+) Get the device identifier
  265. (+) Get the device revision identifier
  266. @endverbatim
  267. * @{
  268. */
  269. /**
  270. * @brief This function is called to increment a global variable "uwTick"
  271. * used as application time base.
  272. * @note In the default implementation, this variable is incremented each 1ms
  273. * in SysTick ISR.
  274. * @note This function is declared as __weak to be overwritten in case of other
  275. * implementations in user file.
  276. * @retval None
  277. */
  278. __weak void HAL_IncTick(void)
  279. {
  280. uwTick += uwTickFreq;
  281. }
  282. /**
  283. * @brief Provides a tick value in millisecond.
  284. * @note This function is declared as __weak to be overwritten in case of other
  285. * implementations in user file.
  286. * @retval tick value
  287. */
  288. __weak uint32_t HAL_GetTick(void)
  289. {
  290. return uwTick;
  291. }
  292. /**
  293. * @brief This function returns a tick priority.
  294. * @retval tick priority
  295. */
  296. uint32_t HAL_GetTickPrio(void)
  297. {
  298. return uwTickPrio;
  299. }
  300. /**
  301. * @brief Set new tick Freq.
  302. * @retval status
  303. */
  304. HAL_StatusTypeDef HAL_SetTickFreq(uint32_t Freq)
  305. {
  306. HAL_StatusTypeDef status = HAL_OK;
  307. assert_param(IS_TICKFREQ(Freq));
  308. if (uwTickFreq != Freq)
  309. {
  310. /* Apply the new tick Freq */
  311. status = HAL_InitTick(uwTickPrio);
  312. if (status == HAL_OK)
  313. {
  314. uwTickFreq = Freq;
  315. }
  316. }
  317. return status;
  318. }
  319. /**
  320. * @brief return tick frequency.
  321. * @retval tick period in Hz
  322. */
  323. uint32_t HAL_GetTickFreq(void)
  324. {
  325. return uwTickFreq;
  326. }
  327. /**
  328. * @brief This function provides minimum delay (in milliseconds) based
  329. * on variable incremented.
  330. * @note In the default implementation , SysTick timer is the source of time base.
  331. * It is used to generate interrupts at regular time intervals where uwTick
  332. * is incremented.
  333. * @note This function is declared as __weak to be overwritten in case of other
  334. * implementations in user file.
  335. * @param Delay specifies the delay time length, in milliseconds.
  336. * @retval None
  337. */
  338. __weak void HAL_Delay(uint32_t Delay)
  339. {
  340. uint32_t tickstart = HAL_GetTick();
  341. uint32_t wait = Delay;
  342. /* Add a freq to guarantee minimum wait */
  343. if (wait < HAL_MAX_DELAY)
  344. {
  345. wait += (uint32_t)(uwTickFreq);
  346. }
  347. while ((HAL_GetTick() - tickstart) < wait)
  348. {
  349. }
  350. }
  351. /**
  352. * @brief Suspend Tick increment.
  353. * @note In the default implementation , SysTick timer is the source of time base. It is
  354. * used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
  355. * is called, the SysTick interrupt will be disabled and so Tick increment
  356. * is suspended.
  357. * @note This function is declared as __weak to be overwritten in case of other
  358. * implementations in user file.
  359. * @retval None
  360. */
  361. __weak void HAL_SuspendTick(void)
  362. {
  363. /* Disable SysTick Interrupt */
  364. CLEAR_BIT(SysTick->CTRL,SysTick_CTRL_TICKINT_Msk);
  365. }
  366. /**
  367. * @brief Resume Tick increment.
  368. * @note In the default implementation , SysTick timer is the source of time base. It is
  369. * used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
  370. * is called, the SysTick interrupt will be enabled and so Tick increment
  371. * is resumed.
  372. * @note This function is declared as __weak to be overwritten in case of other
  373. * implementations in user file.
  374. * @retval None
  375. */
  376. __weak void HAL_ResumeTick(void)
  377. {
  378. /* Enable SysTick Interrupt */
  379. SET_BIT(SysTick->CTRL, SysTick_CTRL_TICKINT_Msk);
  380. }
  381. /**
  382. * @brief Returns the HAL revision
  383. * @retval version : 0xXYZR (8bits for each decimal, R for RC)
  384. */
  385. uint32_t HAL_GetHalVersion(void)
  386. {
  387. return __PY32F002B_HAL_VERSION;
  388. }
  389. /**
  390. * @brief Returns the device revision identifier.
  391. * @retval Device revision identifier
  392. */
  393. uint32_t HAL_GetREVID(void)
  394. {
  395. return ((DBGMCU->IDCODE & DBGMCU_IDCODE_REV_ID) >> 16U);
  396. }
  397. /**
  398. * @brief Returns the device identifier.
  399. * @retval Device identifier
  400. */
  401. uint32_t HAL_GetDEVID(void)
  402. {
  403. return ((DBGMCU->IDCODE) & DBGMCU_IDCODE_DEV_ID);
  404. }
  405. /**
  406. * @brief Returns first word of the unique device identifier (UID based on 96 bits)
  407. * @retval Device identifier
  408. */
  409. uint32_t HAL_GetUIDw0(void)
  410. {
  411. return (READ_REG(*((uint32_t *)UID_BASE)));
  412. }
  413. /**
  414. * @brief Returns second word of the unique device identifier (UID based on 96 bits)
  415. * @retval Device identifier
  416. */
  417. uint32_t HAL_GetUIDw1(void)
  418. {
  419. return (READ_REG(*((uint32_t *)(UID_BASE + 4U))));
  420. }
  421. /**
  422. * @brief Returns third word of the unique device identifier (UID based on 96 bits)
  423. * @retval Device identifier
  424. */
  425. uint32_t HAL_GetUIDw2(void)
  426. {
  427. return (READ_REG(*((uint32_t *)(UID_BASE + 8U))));
  428. }
  429. /**
  430. * @}
  431. */
  432. /** @addtogroup HAL_Exported_Functions_Group3 HAL Debug functions
  433. * @brief HAL Debug functions
  434. *
  435. @verbatim
  436. ===============================================================================
  437. ##### HAL Debug functions #####
  438. ===============================================================================
  439. [..] This section provides functions allowing to:
  440. (+) Enable/Disable Debug module during STOP mode
  441. @endverbatim
  442. * @{
  443. */
  444. /**
  445. * @brief Enable the Debug Module during STOP mode
  446. * @retval None
  447. */
  448. void HAL_DBGMCU_EnableDBGMCUStopMode(void)
  449. {
  450. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
  451. }
  452. /**
  453. * @brief Disable the Debug Module during STOP mode
  454. * @retval None
  455. */
  456. void HAL_DBGMCU_DisableDBGMCUStopMode(void)
  457. {
  458. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOP);
  459. }
  460. /**
  461. * @}
  462. */
  463. /** @addtogroup HAL_Exported_Functions_Group4 SYSCFG configuration functions
  464. * @brief SYSCFG configuration functions
  465. *
  466. @verbatim
  467. ===============================================================================
  468. ##### HAL SYSCFG configuration functions #####
  469. ===============================================================================
  470. [..] This section provides functions allowing to:
  471. (+) Set/Get memory mapping at address 0x00000000
  472. (+) Set/Get TIM1 CH1 Input Source
  473. (+) Enable/Disable I2C Fast mode plus
  474. (+) Set TIM1 ETR Source
  475. (+) Enable/Disable GPIO Noise Filter
  476. (*) Feature not available on all devices
  477. @endverbatim
  478. * @{
  479. */
  480. /**
  481. * @brief Set memory mapping at address 0x00000000
  482. * @param Memory This parameter can be one of the following values:
  483. * @arg @ref SYSCFG_BOOT_MAINFLASH
  484. * @arg @ref SYSCFG_BOOT_SYSTEMFLASH
  485. * @arg @ref SYSCFG_BOOT_SRAM
  486. * @retval None
  487. */
  488. void HAL_SYSCFG_SetRemapMemory(uint32_t Memory)
  489. {
  490. MODIFY_REG(SYSCFG->CFGR1, SYSCFG_CFGR1_MEM_MODE, Memory);
  491. }
  492. /**
  493. * @brief Get memory mapping at address 0x00000000
  494. * @retval Returned value can be one of the following values:
  495. * @arg @ref SYSCFG_BOOT_MAINFLASH
  496. * @arg @ref SYSCFG_BOOT_SYSTEMFLASH
  497. * @arg @ref SYSCFG_BOOT_SRAM
  498. */
  499. uint32_t HAL_SYSCFG_GetRemapMemory(void)
  500. {
  501. return (uint32_t)(READ_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_MEM_MODE));
  502. }
  503. /**
  504. * @brief Set TIM1 CH1 Input Source.
  505. * @param Source TIM1 CH1 Input Source.
  506. * This parameter can be one of the following values:
  507. * @arg SYSCFG_CH1_SRC_TIM1_GPIO
  508. * @arg SYSCFG_CH1_SRC_TIM1_COMP1
  509. * @arg SYSCFG_CH1_SRC_TIM1_COMP2
  510. * @retval None
  511. */
  512. void HAL_SYSCFG_SetTIM1CH1Source(uint32_t Source)
  513. {
  514. MODIFY_REG(SYSCFG->CFGR1, SYSCFG_CFGR1_TIM1_IC1_SRC, Source);
  515. }
  516. /**
  517. * @brief Get TIM1 CH1 Input Source.
  518. * @retval Returned value can be one of the following values:
  519. * @arg @ref SYSCFG_CH1_SRC_TIM1_GPIO
  520. * @arg @ref SYSCFG_CH1_SRC_TIM1_COMP1
  521. * @arg @ref SYSCFG_CH1_SRC_TIM1_COMP2
  522. */
  523. uint32_t HAL_SYSCFG_GetTIM1CH1Source(void)
  524. {
  525. return (uint32_t)(READ_BIT(SYSCFG->CFGR1, SYSCFG_CFGR1_TIM1_IC1_SRC));
  526. }
  527. /**
  528. * @brief Enable I2C Fast mode plus
  529. * @note Depending on devices and packages, some IOs may not be available.
  530. * Refer to device datasheet for IOs availability.
  531. * @param I2CFastModePlus This parameter can be a combination of the following values:
  532. * @arg @ref SYSCFG_I2C_FMP_PA2
  533. * @arg @ref SYSCFG_I2C_FMP_PB3
  534. * @arg @ref SYSCFG_I2C_FMP_PB4
  535. * @arg @ref SYSCFG_I2C_FMP_PB6
  536. * @retval None
  537. */
  538. void HAL_SYSCFG_EnableI2CFastModePlus(uint32_t I2CFastModePlus)
  539. {
  540. SET_BIT(SYSCFG->CFGR1, I2CFastModePlus);
  541. }
  542. /**
  543. * @brief Disable I2C Fast mode plus
  544. * @note Depending on devices and packages, some IOs may not be available.
  545. * Refer to device datasheet for IOs availability.
  546. * @param I2CFastModePlus This parameter can be a combination of the following values:
  547. * @arg @ref SYSCFG_I2C_FMP_PA2
  548. * @arg @ref SYSCFG_I2C_FMP_PB3
  549. * @arg @ref SYSCFG_I2C_FMP_PB4
  550. * @arg @ref SYSCFG_I2C_FMP_PB6
  551. * @retval None
  552. */
  553. void HAL_SYSCFG_DisableI2CFastModePlus(uint32_t I2CFastModePlus)
  554. {
  555. CLEAR_BIT(SYSCFG->CFGR1, I2CFastModePlus);
  556. }
  557. #if defined(SYSCFG_CFGR2_ETR_SRC_TIM1)
  558. /**
  559. * @brief Set TIM1 ETR Source
  560. * @param ETRSource TIM1 ETR Source.
  561. * This parameter can be one of the following values:
  562. * @arg SYSCFG_ETR_SRC_TIM1_GPIO: GPIO for TIM1 ETR Source
  563. * @arg SYSCFG_ETR_SRC_TIM1_COMP1: COMP1 for TIM1 ETR Source
  564. * @arg SYSCFG_ETR_SRC_TIM1_COMP2: COMP2 for TIM1 ETR Source
  565. * @arg SYSCFG_ETR_SRC_TIM1_ADC: ADC for TIM1 ETR Source
  566. * @retval None
  567. */
  568. void HAL_SYSCFG_TIM1ETRSource(uint32_t ETRSource)
  569. {
  570. MODIFY_REG(SYSCFG->CFGR2, SYSCFG_CFGR2_ETR_SRC_TIM1, ETRSource);
  571. }
  572. #endif
  573. #if (defined(SYSCFG_GPIO_ENS_PA_ENS) || defined(SYSCFG_GPIO_ENS_PB_ENS) || defined(SYSCFG_GPIO_ENS_PC_ENS))
  574. /**
  575. * @brief Enable GPIO Noise Filter
  576. * @note Depending on devices and packages, some IOs may not be available.
  577. * Refer to device datasheet for IOs availability.
  578. * @param GPIOx where x can be (A..C) to select the GPIO peripheral for PY32F002B family
  579. * @param GPIO_Pin specifies the pin to be Noise Filter
  580. * This parameter can be any combination of GPIO_Pin_x where x can be (0..7).
  581. * @retval None
  582. */
  583. void HAL_SYSCFG_EnableGPIONoiseFilter(GPIO_TypeDef *GPIOx,uint16_t GPIO_Pin)
  584. {
  585. /* Check the parameters */
  586. assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
  587. assert_param(IS_GPIO_PIN(GPIO_Pin));
  588. if(GPIOx == GPIOA)
  589. {
  590. SET_BIT(SYSCFG->GPIO_ENS, GPIO_Pin);
  591. }
  592. else if(GPIOx == GPIOB)
  593. {
  594. SET_BIT(SYSCFG->GPIO_ENS, (GPIO_Pin << 8U));
  595. }
  596. else if(GPIOx == GPIOC)
  597. {
  598. SET_BIT(SYSCFG->GPIO_ENS, (GPIO_Pin << 16U));
  599. }
  600. else
  601. {
  602. }
  603. }
  604. /**
  605. * @brief Disable GPIO Noise Filter
  606. * @note Depending on devices and packages, some IOs may not be available.
  607. * Refer to device datasheet for IOs availability.
  608. * @param GPIOx where x can be (A..C) to select the GPIO peripheral for PY32F002B family
  609. * @param GPIO_Pin specifies the pin to be Noise Filter
  610. * This parameter can be any combination of GPIO_Pin_x where x can be (0..7).
  611. * @retval None
  612. */
  613. void HAL_SYSCFG_DisableGPIONoiseFilter(GPIO_TypeDef *GPIOx,uint16_t GPIO_Pin)
  614. {
  615. /* Check the parameters */
  616. assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
  617. assert_param(IS_GPIO_PIN(GPIO_Pin));
  618. if(GPIOx == GPIOA)
  619. {
  620. CLEAR_BIT(SYSCFG->GPIO_ENS, GPIO_Pin);
  621. }
  622. else if(GPIOx == GPIOB)
  623. {
  624. CLEAR_BIT(SYSCFG->GPIO_ENS, (GPIO_Pin << 8U));
  625. }
  626. else if(GPIOx == GPIOC)
  627. {
  628. CLEAR_BIT(SYSCFG->GPIO_ENS, (GPIO_Pin << 16U));
  629. }
  630. else
  631. {
  632. }
  633. }
  634. #endif
  635. /**
  636. * @}
  637. */
  638. /**
  639. * @}
  640. */
  641. #endif /* HAL_MODULE_ENABLED */
  642. /**
  643. * @}
  644. */
  645. /**
  646. * @}
  647. */
  648. /************************ (C) COPYRIGHT Puya *****END OF FILE****/