stm32h7xx_hal.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_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) 2017 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 "stm32h7xx_hal.h"
  35. /** @addtogroup STM32H7xx_HAL_Driver
  36. * @{
  37. */
  38. /** @defgroup HAL HAL
  39. * @brief HAL module driver.
  40. * @{
  41. */
  42. /* Private typedef -----------------------------------------------------------*/
  43. /* Private define ------------------------------------------------------------*/
  44. /**
  45. * @brief STM32H7xx HAL Driver version number
  46. */
  47. #define __STM32H7xx_HAL_VERSION_MAIN (0x01UL) /*!< [31:24] main version */
  48. #define __STM32H7xx_HAL_VERSION_SUB1 (0x0BUL) /*!< [23:16] sub1 version */
  49. #define __STM32H7xx_HAL_VERSION_SUB2 (0x03UL) /*!< [15:8] sub2 version */
  50. #define __STM32H7xx_HAL_VERSION_RC (0x00UL) /*!< [7:0] release candidate */
  51. #define __STM32H7xx_HAL_VERSION ((__STM32H7xx_HAL_VERSION_MAIN << 24)\
  52. |(__STM32H7xx_HAL_VERSION_SUB1 << 16)\
  53. |(__STM32H7xx_HAL_VERSION_SUB2 << 8 )\
  54. |(__STM32H7xx_HAL_VERSION_RC))
  55. #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF)
  56. #define VREFBUF_TIMEOUT_VALUE (uint32_t)10 /* 10 ms */
  57. /* Private macro -------------------------------------------------------------*/
  58. /* Private variables ---------------------------------------------------------*/
  59. /* Exported variables --------------------------------------------------------*/
  60. /** @defgroup HAL_Exported_Variables HAL Exported Variables
  61. * @{
  62. */
  63. __IO uint32_t uwTick;
  64. uint32_t uwTickPrio = (1UL << __NVIC_PRIO_BITS); /* Invalid PRIO */
  65. HAL_TickFreqTypeDef uwTickFreq = HAL_TICK_FREQ_DEFAULT; /* 1KHz */
  66. /**
  67. * @}
  68. */
  69. /* Private function prototypes -----------------------------------------------*/
  70. /* Private functions ---------------------------------------------------------*/
  71. /** @addtogroup HAL_Exported_Functions
  72. * @{
  73. */
  74. /** @addtogroup HAL_Group1
  75. * @brief Initialization and de-initialization functions
  76. *
  77. @verbatim
  78. ===============================================================================
  79. ##### Initialization and de-initialization functions #####
  80. ===============================================================================
  81. [..] This section provides functions allowing to:
  82. (+) Initializes the Flash interface the NVIC allocation and initial clock
  83. configuration. It initializes the systick also when timeout is needed
  84. and the backup domain when enabled.
  85. (+) De-Initializes common part of the HAL.
  86. (+) Configure The time base source to have 1ms time base with a dedicated
  87. Tick interrupt priority.
  88. (++) SysTick timer is used by default as source of time base, but user
  89. can eventually implement his proper time base source (a general purpose
  90. timer for example or other time source), keeping in mind that Time base
  91. duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and
  92. handled in milliseconds basis.
  93. (++) Time base configuration function (HAL_InitTick ()) is called automatically
  94. at the beginning of the program after reset by HAL_Init() or at any time
  95. when clock is configured, by HAL_RCC_ClockConfig().
  96. (++) Source of time base is configured to generate interrupts at regular
  97. time intervals. Care must be taken if HAL_Delay() is called from a
  98. peripheral ISR process, the Tick interrupt line must have higher priority
  99. (numerically lower) than the peripheral interrupt. Otherwise the caller
  100. ISR process will be blocked.
  101. (++) functions affecting time base configurations are declared as __weak
  102. to make override possible in case of other implementations in user file.
  103. @endverbatim
  104. * @{
  105. */
  106. /**
  107. * @brief This function is used to initialize the HAL Library; it must be the first
  108. * instruction to be executed in the main program (before to call any other
  109. * HAL function), it performs the following:
  110. * Configures the SysTick to generate an interrupt each 1 millisecond,
  111. * which is clocked by the HSI (at this stage, the clock is not yet
  112. * configured and thus the system is running from the internal HSI at 16 MHz).
  113. * Set NVIC Group Priority to 4.
  114. * Calls the HAL_MspInit() callback function defined in user file
  115. * "stm32h7xx_hal_msp.c" to do the global low level hardware initialization
  116. *
  117. * @note SysTick is used as time base for the HAL_Delay() function, the application
  118. * need to ensure that the SysTick time base is always set to 1 millisecond
  119. * to have correct HAL operation.
  120. * @retval HAL status
  121. */
  122. HAL_StatusTypeDef HAL_Init(void)
  123. {
  124. uint32_t common_system_clock;
  125. #if defined(DUAL_CORE) && defined(CORE_CM4)
  126. /* Configure Cortex-M4 Instruction cache through ART accelerator */
  127. __HAL_RCC_ART_CLK_ENABLE(); /* Enable the Cortex-M4 ART Clock */
  128. __HAL_ART_CONFIG_BASE_ADDRESS(0x08100000UL); /* Configure the Cortex-M4 ART Base address to the Flash Bank 2 : */
  129. __HAL_ART_ENABLE(); /* Enable the Cortex-M4 ART */
  130. #endif /* DUAL_CORE && CORE_CM4 */
  131. /* Set Interrupt Group Priority */
  132. HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
  133. /* Update the SystemCoreClock global variable */
  134. #if defined(RCC_D1CFGR_D1CPRE)
  135. common_system_clock = HAL_RCC_GetSysClockFreq() >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_D1CPRE)>> RCC_D1CFGR_D1CPRE_Pos]) & 0x1FU);
  136. #else
  137. common_system_clock = HAL_RCC_GetSysClockFreq() >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_CDCPRE)>> RCC_CDCFGR1_CDCPRE_Pos]) & 0x1FU);
  138. #endif
  139. /* Update the SystemD2Clock global variable */
  140. #if defined(RCC_D1CFGR_HPRE)
  141. SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE)>> RCC_D1CFGR_HPRE_Pos]) & 0x1FU));
  142. #else
  143. SystemD2Clock = (common_system_clock >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_HPRE)>> RCC_CDCFGR1_HPRE_Pos]) & 0x1FU));
  144. #endif
  145. #if defined(DUAL_CORE) && defined(CORE_CM4)
  146. SystemCoreClock = SystemD2Clock;
  147. #else
  148. SystemCoreClock = common_system_clock;
  149. #endif /* DUAL_CORE && CORE_CM4 */
  150. /* Use systick as time base source and configure 1ms tick (default clock after Reset is HSI) */
  151. if(HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK)
  152. {
  153. return HAL_ERROR;
  154. }
  155. /* Init the low level hardware */
  156. HAL_MspInit();
  157. /* Return function status */
  158. return HAL_OK;
  159. }
  160. /**
  161. * @brief This function de-Initializes common part of the HAL and stops the systick.
  162. * This function is optional.
  163. * @retval HAL status
  164. */
  165. HAL_StatusTypeDef HAL_DeInit(void)
  166. {
  167. /* Reset of all peripherals */
  168. __HAL_RCC_AHB3_FORCE_RESET();
  169. __HAL_RCC_AHB3_RELEASE_RESET();
  170. __HAL_RCC_AHB1_FORCE_RESET();
  171. __HAL_RCC_AHB1_RELEASE_RESET();
  172. __HAL_RCC_AHB2_FORCE_RESET();
  173. __HAL_RCC_AHB2_RELEASE_RESET();
  174. __HAL_RCC_AHB4_FORCE_RESET();
  175. __HAL_RCC_AHB4_RELEASE_RESET();
  176. __HAL_RCC_APB3_FORCE_RESET();
  177. __HAL_RCC_APB3_RELEASE_RESET();
  178. __HAL_RCC_APB1L_FORCE_RESET();
  179. __HAL_RCC_APB1L_RELEASE_RESET();
  180. __HAL_RCC_APB1H_FORCE_RESET();
  181. __HAL_RCC_APB1H_RELEASE_RESET();
  182. __HAL_RCC_APB2_FORCE_RESET();
  183. __HAL_RCC_APB2_RELEASE_RESET();
  184. __HAL_RCC_APB4_FORCE_RESET();
  185. __HAL_RCC_APB4_RELEASE_RESET();
  186. /* De-Init the low level hardware */
  187. HAL_MspDeInit();
  188. /* Return function status */
  189. return HAL_OK;
  190. }
  191. /**
  192. * @brief Initializes the MSP.
  193. * @retval None
  194. */
  195. __weak void HAL_MspInit(void)
  196. {
  197. /* NOTE : This function Should not be modified, when the callback is needed,
  198. the HAL_MspInit could be implemented in the user file
  199. */
  200. }
  201. /**
  202. * @brief DeInitializes the MSP.
  203. * @retval None
  204. */
  205. __weak void HAL_MspDeInit(void)
  206. {
  207. /* NOTE : This function Should not be modified, when the callback is needed,
  208. the HAL_MspDeInit could be implemented in the user file
  209. */
  210. }
  211. /**
  212. * @brief This function configures the source of the time base.
  213. * The time source is configured to have 1ms time base with a dedicated
  214. * Tick interrupt priority.
  215. * @note This function is called automatically at the beginning of program after
  216. * reset by HAL_Init() or at any time when clock is reconfigured by HAL_RCC_ClockConfig().
  217. * @note In the default implementation, SysTick timer is the source of time base.
  218. * It is used to generate interrupts at regular time intervals.
  219. * Care must be taken if HAL_Delay() is called from a peripheral ISR process,
  220. * the SysTick interrupt must have higher priority (numerically lower)
  221. * than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
  222. * The function is declared as __weak to be overwritten in case of other
  223. * implementation in user file.
  224. * @param TickPriority: Tick interrupt priority.
  225. * @retval HAL status
  226. */
  227. __weak HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
  228. {
  229. /* Check uwTickFreq for MisraC 2012 (even if uwTickFreq is a enum type that don't take the value zero)*/
  230. if((uint32_t)uwTickFreq == 0UL)
  231. {
  232. return HAL_ERROR;
  233. }
  234. /* Configure the SysTick to have interrupt in 1ms time basis*/
  235. if (HAL_SYSTICK_Config(SystemCoreClock / (1000UL / (uint32_t)uwTickFreq)) > 0U)
  236. {
  237. return HAL_ERROR;
  238. }
  239. /* Configure the SysTick IRQ priority */
  240. if (TickPriority < (1UL << __NVIC_PRIO_BITS))
  241. {
  242. HAL_NVIC_SetPriority(SysTick_IRQn, TickPriority, 0U);
  243. uwTickPrio = TickPriority;
  244. }
  245. else
  246. {
  247. return HAL_ERROR;
  248. }
  249. /* Return function status */
  250. return HAL_OK;
  251. }
  252. /**
  253. * @}
  254. */
  255. /** @addtogroup HAL_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 identifier
  269. (+) Get the device revision identifier
  270. (+) Enable/Disable Debug module during SLEEP mode
  271. (+) Enable/Disable Debug module during STOP mode
  272. (+) Enable/Disable Debug module during STANDBY mode
  273. @endverbatim
  274. * @{
  275. */
  276. /**
  277. * @brief This function is called to increment a global variable "uwTick"
  278. * used as application time base.
  279. * @note In the default implementation, this variable is incremented each 1ms
  280. * in Systick ISR.
  281. * @note This function is declared as __weak to be overwritten in case of other
  282. * implementations in user file.
  283. * @retval None
  284. */
  285. __weak void HAL_IncTick(void)
  286. {
  287. uwTick += (uint32_t)uwTickFreq;
  288. }
  289. /**
  290. * @brief Provides a tick value in millisecond.
  291. * @note This function is declared as __weak to be overwritten in case of other
  292. * implementations in user file.
  293. * @retval tick value
  294. */
  295. __weak uint32_t HAL_GetTick(void)
  296. {
  297. return uwTick;
  298. }
  299. /**
  300. * @brief This function returns a tick priority.
  301. * @retval tick priority
  302. */
  303. uint32_t HAL_GetTickPrio(void)
  304. {
  305. return uwTickPrio;
  306. }
  307. /**
  308. * @brief Set new tick Freq.
  309. * @retval Status
  310. */
  311. HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq)
  312. {
  313. HAL_StatusTypeDef status = HAL_OK;
  314. HAL_TickFreqTypeDef prevTickFreq;
  315. assert_param(IS_TICKFREQ(Freq));
  316. if (uwTickFreq != Freq)
  317. {
  318. /* Back up uwTickFreq frequency */
  319. prevTickFreq = uwTickFreq;
  320. /* Update uwTickFreq global variable used by HAL_InitTick() */
  321. uwTickFreq = Freq;
  322. /* Apply the new tick Freq */
  323. status = HAL_InitTick(uwTickPrio);
  324. if (status != HAL_OK)
  325. {
  326. /* Restore previous tick frequency */
  327. uwTickFreq = prevTickFreq;
  328. }
  329. }
  330. return status;
  331. }
  332. /**
  333. * @brief Return tick frequency.
  334. * @retval Tick frequency.
  335. * Value of @ref HAL_TickFreqTypeDef.
  336. */
  337. HAL_TickFreqTypeDef HAL_GetTickFreq(void)
  338. {
  339. return uwTickFreq;
  340. }
  341. /**
  342. * @brief This function provides minimum delay (in milliseconds) based
  343. * on variable incremented.
  344. * @note In the default implementation , SysTick timer is the source of time base.
  345. * It is used to generate interrupts at regular time intervals where uwTick
  346. * is incremented.
  347. * @note This function is declared as __weak to be overwritten in case of other
  348. * implementations in user file.
  349. * @param Delay specifies the delay time length, in milliseconds.
  350. * @retval None
  351. */
  352. __weak void HAL_Delay(uint32_t Delay)
  353. {
  354. uint32_t tickstart = HAL_GetTick();
  355. uint32_t wait = Delay;
  356. /* Add a freq to guarantee minimum wait */
  357. if (wait < HAL_MAX_DELAY)
  358. {
  359. wait += (uint32_t)(uwTickFreq);
  360. }
  361. while ((HAL_GetTick() - tickstart) < wait)
  362. {
  363. }
  364. }
  365. /**
  366. * @brief Suspend Tick increment.
  367. * @note In the default implementation , SysTick timer is the source of time base. It is
  368. * used to generate interrupts at regular time intervals. Once HAL_SuspendTick()
  369. * is called, the SysTick interrupt will be disabled and so Tick increment
  370. * is suspended.
  371. * @note This function is declared as __weak to be overwritten in case of other
  372. * implementations in user file.
  373. * @retval None
  374. */
  375. __weak void HAL_SuspendTick(void)
  376. {
  377. /* Disable SysTick Interrupt */
  378. SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
  379. }
  380. /**
  381. * @brief Resume Tick increment.
  382. * @note In the default implementation , SysTick timer is the source of time base. It is
  383. * used to generate interrupts at regular time intervals. Once HAL_ResumeTick()
  384. * is called, the SysTick interrupt will be enabled and so Tick increment
  385. * is resumed.
  386. * @note This function is declared as __weak to be overwritten in case of other
  387. * implementations in user file.
  388. * @retval None
  389. */
  390. __weak void HAL_ResumeTick(void)
  391. {
  392. /* Enable SysTick Interrupt */
  393. SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk;
  394. }
  395. /**
  396. * @brief Returns the HAL revision
  397. * @retval version : 0xXYZR (8bits for each decimal, R for RC)
  398. */
  399. uint32_t HAL_GetHalVersion(void)
  400. {
  401. return __STM32H7xx_HAL_VERSION;
  402. }
  403. /**
  404. * @brief Returns the device revision identifier.
  405. * @retval Device revision identifier
  406. */
  407. uint32_t HAL_GetREVID(void)
  408. {
  409. return((DBGMCU->IDCODE) >> 16);
  410. }
  411. /**
  412. * @brief Returns the device identifier.
  413. * @retval Device identifier
  414. */
  415. uint32_t HAL_GetDEVID(void)
  416. {
  417. return((DBGMCU->IDCODE) & IDCODE_DEVID_MASK);
  418. }
  419. /**
  420. * @brief Return the first word of the unique device identifier (UID based on 96 bits)
  421. * @retval Device identifier
  422. */
  423. uint32_t HAL_GetUIDw0(void)
  424. {
  425. return(READ_REG(*((uint32_t *)UID_BASE)));
  426. }
  427. /**
  428. * @brief Return the second word of the unique device identifier (UID based on 96 bits)
  429. * @retval Device identifier
  430. */
  431. uint32_t HAL_GetUIDw1(void)
  432. {
  433. return(READ_REG(*((uint32_t *)(UID_BASE + 4U))));
  434. }
  435. /**
  436. * @brief Return the third word of the unique device identifier (UID based on 96 bits)
  437. * @retval Device identifier
  438. */
  439. uint32_t HAL_GetUIDw2(void)
  440. {
  441. return(READ_REG(*((uint32_t *)(UID_BASE + 8U))));
  442. }
  443. /**
  444. * @brief Configure the internal voltage reference buffer voltage scale.
  445. * @param VoltageScaling specifies the output voltage to achieve
  446. * This parameter can be one of the following values:
  447. * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE0: VREF_OUT1 around 2.5 V.
  448. * This requires VDDA equal to or higher than 2.8 V.
  449. * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE1: VREF_OUT2 around 2.048 V.
  450. * This requires VDDA equal to or higher than 2.4 V.
  451. * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE2: VREF_OUT3 around 1.8 V.
  452. * This requires VDDA equal to or higher than 2.1 V.
  453. * @arg SYSCFG_VREFBUF_VOLTAGE_SCALE3: VREF_OUT4 around 1.5 V.
  454. * This requires VDDA equal to or higher than 1.8 V.
  455. * @retval None
  456. */
  457. void HAL_SYSCFG_VREFBUF_VoltageScalingConfig(uint32_t VoltageScaling)
  458. {
  459. /* Check the parameters */
  460. assert_param(IS_SYSCFG_VREFBUF_VOLTAGE_SCALE(VoltageScaling));
  461. MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_VRS, VoltageScaling);
  462. }
  463. /**
  464. * @brief Configure the internal voltage reference buffer high impedance mode.
  465. * @param Mode specifies the high impedance mode
  466. * This parameter can be one of the following values:
  467. * @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_DISABLE: VREF+ pin is internally connect to VREFINT output.
  468. * @arg SYSCFG_VREFBUF_HIGH_IMPEDANCE_ENABLE: VREF+ pin is high impedance.
  469. * @retval None
  470. */
  471. void HAL_SYSCFG_VREFBUF_HighImpedanceConfig(uint32_t Mode)
  472. {
  473. /* Check the parameters */
  474. assert_param(IS_SYSCFG_VREFBUF_HIGH_IMPEDANCE(Mode));
  475. MODIFY_REG(VREFBUF->CSR, VREFBUF_CSR_HIZ, Mode);
  476. }
  477. /**
  478. * @brief Tune the Internal Voltage Reference buffer (VREFBUF).
  479. * @retval None
  480. */
  481. void HAL_SYSCFG_VREFBUF_TrimmingConfig(uint32_t TrimmingValue)
  482. {
  483. /* Check the parameters */
  484. assert_param(IS_SYSCFG_VREFBUF_TRIMMING(TrimmingValue));
  485. MODIFY_REG(VREFBUF->CCR, VREFBUF_CCR_TRIM, TrimmingValue);
  486. }
  487. /**
  488. * @brief Enable the Internal Voltage Reference buffer (VREFBUF).
  489. * @retval HAL_OK/HAL_TIMEOUT
  490. */
  491. HAL_StatusTypeDef HAL_SYSCFG_EnableVREFBUF(void)
  492. {
  493. uint32_t tickstart;
  494. SET_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
  495. /* Get Start Tick*/
  496. tickstart = HAL_GetTick();
  497. /* Wait for VRR bit */
  498. while(READ_BIT(VREFBUF->CSR, VREFBUF_CSR_VRR) == 0UL)
  499. {
  500. if((HAL_GetTick() - tickstart) > VREFBUF_TIMEOUT_VALUE)
  501. {
  502. return HAL_TIMEOUT;
  503. }
  504. }
  505. return HAL_OK;
  506. }
  507. /**
  508. * @brief Disable the Internal Voltage Reference buffer (VREFBUF).
  509. *
  510. * @retval None
  511. */
  512. void HAL_SYSCFG_DisableVREFBUF(void)
  513. {
  514. CLEAR_BIT(VREFBUF->CSR, VREFBUF_CSR_ENVR);
  515. }
  516. #if defined(SYSCFG_PMCR_EPIS_SEL)
  517. /**
  518. * @brief Ethernet PHY Interface Selection either MII or RMII
  519. * @param SYSCFG_ETHInterface: Selects the Ethernet PHY interface
  520. * This parameter can be one of the following values:
  521. * @arg SYSCFG_ETH_MII : Select the Media Independent Interface
  522. * @arg SYSCFG_ETH_RMII: Select the Reduced Media Independent Interface
  523. * @retval None
  524. */
  525. void HAL_SYSCFG_ETHInterfaceSelect(uint32_t SYSCFG_ETHInterface)
  526. {
  527. /* Check the parameter */
  528. assert_param(IS_SYSCFG_ETHERNET_CONFIG(SYSCFG_ETHInterface));
  529. MODIFY_REG(SYSCFG->PMCR, SYSCFG_PMCR_EPIS_SEL, (uint32_t)(SYSCFG_ETHInterface));
  530. }
  531. #endif /* SYSCFG_PMCR_EPIS_SEL */
  532. /**
  533. * @brief Analog Switch control for dual analog pads.
  534. * @param SYSCFG_AnalogSwitch: Selects the analog pad
  535. * This parameter can be one or a combination of the following values:
  536. * @arg SYSCFG_SWITCH_PA0 : Select PA0 analog switch
  537. * @arg SYSCFG_SWITCH_PA1: Select PA1 analog switch
  538. * @arg SYSCFG_SWITCH_PC2 : Select PC2 analog switch
  539. * @arg SYSCFG_SWITCH_PC3: Select PC3 analog switch
  540. * @param SYSCFG_SwitchState: Open or Close the analog switch between dual pads (PXn and PXn_C)
  541. * This parameter can be one or a combination of the following values:
  542. * @arg SYSCFG_SWITCH_PA0_OPEN
  543. * @arg SYSCFG_SWITCH_PA0_CLOSE
  544. * @arg SYSCFG_SWITCH_PA1_OPEN
  545. * @arg SYSCFG_SWITCH_PA1_CLOSE
  546. * @arg SYSCFG_SWITCH_PC2_OPEN
  547. * @arg SYSCFG_SWITCH_PC2_CLOSE
  548. * @arg SYSCFG_SWITCH_PC3_OPEN
  549. * @arg SYSCFG_SWITCH_PC3_CLOSE
  550. * @retval None
  551. */
  552. void HAL_SYSCFG_AnalogSwitchConfig(uint32_t SYSCFG_AnalogSwitch , uint32_t SYSCFG_SwitchState )
  553. {
  554. /* Check the parameter */
  555. assert_param(IS_SYSCFG_ANALOG_SWITCH(SYSCFG_AnalogSwitch));
  556. assert_param(IS_SYSCFG_SWITCH_STATE(SYSCFG_SwitchState));
  557. MODIFY_REG(SYSCFG->PMCR, (uint32_t) SYSCFG_AnalogSwitch, (uint32_t)(SYSCFG_SwitchState));
  558. }
  559. #if defined(SYSCFG_PMCR_BOOSTEN)
  560. /**
  561. * @brief Enables the booster to reduce the total harmonic distortion of the analog
  562. * switch when the supply voltage is lower than 2.7 V.
  563. * @note Activating the booster allows to guaranty the analog switch AC performance
  564. * when the supply voltage is below 2.7 V: in this case, the analog switch
  565. * performance is the same on the full voltage range
  566. * @retval None
  567. */
  568. void HAL_SYSCFG_EnableBOOST(void)
  569. {
  570. SET_BIT(SYSCFG->PMCR, SYSCFG_PMCR_BOOSTEN) ;
  571. }
  572. /**
  573. * @brief Disables the booster
  574. * @note Activating the booster allows to guaranty the analog switch AC performance
  575. * when the supply voltage is below 2.7 V: in this case, the analog switch
  576. * performance is the same on the full voltage range
  577. * @retval None
  578. */
  579. void HAL_SYSCFG_DisableBOOST(void)
  580. {
  581. CLEAR_BIT(SYSCFG->PMCR, SYSCFG_PMCR_BOOSTEN) ;
  582. }
  583. #endif /* SYSCFG_PMCR_BOOSTEN */
  584. #if defined (SYSCFG_UR2_BOOT_ADD0) || defined (SYSCFG_UR2_BCM7_ADD0)
  585. /**
  586. * @brief BootCM7 address 0 configuration
  587. * @param BootRegister :Specifies the Boot Address register (Address0 or Address1)
  588. * This parameter can be one of the following values:
  589. * @arg SYSCFG_BOOT_ADDR0 : Select the boot address0
  590. * @arg SYSCFG_BOOT_ADDR1: Select the boot address1
  591. * @param BootAddress :Specifies the CM7 Boot Address to be loaded in Address0 or Address1
  592. * @retval None
  593. */
  594. void HAL_SYSCFG_CM7BootAddConfig(uint32_t BootRegister, uint32_t BootAddress)
  595. {
  596. /* Check the parameters */
  597. assert_param(IS_SYSCFG_BOOT_REGISTER(BootRegister));
  598. assert_param(IS_SYSCFG_BOOT_ADDRESS(BootAddress));
  599. if ( BootRegister == SYSCFG_BOOT_ADDR0 )
  600. {
  601. /* Configure CM7 BOOT ADD0 */
  602. #if defined(DUAL_CORE)
  603. MODIFY_REG(SYSCFG->UR2, SYSCFG_UR2_BCM7_ADD0, ((BootAddress >> 16) << SYSCFG_UR2_BCM7_ADD0_Pos));
  604. #else
  605. MODIFY_REG(SYSCFG->UR2, SYSCFG_UR2_BOOT_ADD0, ((BootAddress >> 16) << SYSCFG_UR2_BOOT_ADD0_Pos));
  606. #endif /*DUAL_CORE*/
  607. }
  608. else
  609. {
  610. /* Configure CM7 BOOT ADD1 */
  611. #if defined(DUAL_CORE)
  612. MODIFY_REG(SYSCFG->UR3, SYSCFG_UR3_BCM7_ADD1, (BootAddress >> 16));
  613. #else
  614. MODIFY_REG(SYSCFG->UR3, SYSCFG_UR3_BOOT_ADD1, (BootAddress >> 16));
  615. #endif /*DUAL_CORE*/
  616. }
  617. }
  618. #endif /* SYSCFG_UR2_BOOT_ADD0 || SYSCFG_UR2_BCM7_ADD0 */
  619. #if defined(DUAL_CORE)
  620. /**
  621. * @brief BootCM4 address 0 configuration
  622. * @param BootRegister :Specifies the Boot Address register (Address0 or Address1)
  623. * This parameter can be one of the following values:
  624. * @arg SYSCFG_BOOT_ADDR0 : Select the boot address0
  625. * @arg SYSCFG_BOOT_ADDR1: Select the boot address1
  626. * @param BootAddress :Specifies the CM4 Boot Address to be loaded in Address0 or Address1
  627. * @retval None
  628. */
  629. void HAL_SYSCFG_CM4BootAddConfig(uint32_t BootRegister, uint32_t BootAddress)
  630. {
  631. /* Check the parameters */
  632. assert_param(IS_SYSCFG_BOOT_REGISTER(BootRegister));
  633. assert_param(IS_SYSCFG_BOOT_ADDRESS(BootAddress));
  634. if ( BootRegister == SYSCFG_BOOT_ADDR0 )
  635. {
  636. /* Configure CM4 BOOT ADD0 */
  637. MODIFY_REG(SYSCFG->UR3, SYSCFG_UR3_BCM4_ADD0, ((BootAddress >> 16)<< SYSCFG_UR3_BCM4_ADD0_Pos));
  638. }
  639. else
  640. {
  641. /* Configure CM4 BOOT ADD1 */
  642. MODIFY_REG(SYSCFG->UR4, SYSCFG_UR4_BCM4_ADD1, (BootAddress >> 16));
  643. }
  644. }
  645. /**
  646. * @brief Enables the Cortex-M7 boot
  647. * @retval None
  648. */
  649. void HAL_SYSCFG_EnableCM7BOOT(void)
  650. {
  651. SET_BIT(SYSCFG->UR1, SYSCFG_UR1_BCM7);
  652. }
  653. /**
  654. * @brief Disables the Cortex-M7 boot
  655. * @note Disabling the boot will gate the CPU clock
  656. * @retval None
  657. */
  658. void HAL_SYSCFG_DisableCM7BOOT(void)
  659. {
  660. CLEAR_BIT(SYSCFG->UR1, SYSCFG_UR1_BCM7) ;
  661. }
  662. /**
  663. * @brief Enables the Cortex-M4 boot
  664. * @retval None
  665. */
  666. void HAL_SYSCFG_EnableCM4BOOT(void)
  667. {
  668. SET_BIT(SYSCFG->UR1, SYSCFG_UR1_BCM4);
  669. }
  670. /**
  671. * @brief Disables the Cortex-M4 boot
  672. * @note Disabling the boot will gate the CPU clock
  673. * @retval None
  674. */
  675. void HAL_SYSCFG_DisableCM4BOOT(void)
  676. {
  677. CLEAR_BIT(SYSCFG->UR1, SYSCFG_UR1_BCM4);
  678. }
  679. #endif /*DUAL_CORE*/
  680. /**
  681. * @brief Enables the I/O Compensation Cell.
  682. * @note The I/O compensation cell can be used only when the device supply
  683. * voltage ranges from 1.62 to 2.0 V and from 2.7 to 3.6 V.
  684. * @retval None
  685. */
  686. void HAL_EnableCompensationCell(void)
  687. {
  688. SET_BIT(SYSCFG->CCCSR, SYSCFG_CCCSR_EN) ;
  689. }
  690. /**
  691. * @brief Power-down the I/O Compensation Cell.
  692. * @note The I/O compensation cell can be used only when the device supply
  693. * voltage ranges from 1.62 to 2.0 V and from 2.7 to 3.6 V.
  694. * @retval None
  695. */
  696. void HAL_DisableCompensationCell(void)
  697. {
  698. CLEAR_BIT(SYSCFG->CCCSR, SYSCFG_CCCSR_EN);
  699. }
  700. /**
  701. * @brief To Enable optimize the I/O speed when the product voltage is low.
  702. * @note This bit is active only if PRODUCT_BELOW_25V user option bit is set. It must be
  703. * used only if the product supply voltage is below 2.5 V. Setting this bit when VDD is
  704. * higher than 2.5 V might be destructive.
  705. * @retval None
  706. */
  707. void HAL_SYSCFG_EnableIOSpeedOptimize(void)
  708. {
  709. #if defined(SYSCFG_CCCSR_HSLV)
  710. SET_BIT(SYSCFG->CCCSR, SYSCFG_CCCSR_HSLV);
  711. #else
  712. SET_BIT(SYSCFG->CCCSR, (SYSCFG_CCCSR_HSLV0| SYSCFG_CCCSR_HSLV1 | SYSCFG_CCCSR_HSLV2 | SYSCFG_CCCSR_HSLV3));
  713. #endif /* SYSCFG_CCCSR_HSLV */
  714. }
  715. /**
  716. * @brief To Disable optimize the I/O speed when the product voltage is low.
  717. * @note This bit is active only if PRODUCT_BELOW_25V user option bit is set. It must be
  718. * used only if the product supply voltage is below 2.5 V. Setting this bit when VDD is
  719. * higher than 2.5 V might be destructive.
  720. * @retval None
  721. */
  722. void HAL_SYSCFG_DisableIOSpeedOptimize(void)
  723. {
  724. #if defined(SYSCFG_CCCSR_HSLV)
  725. CLEAR_BIT(SYSCFG->CCCSR, SYSCFG_CCCSR_HSLV);
  726. #else
  727. CLEAR_BIT(SYSCFG->CCCSR, (SYSCFG_CCCSR_HSLV0| SYSCFG_CCCSR_HSLV1 | SYSCFG_CCCSR_HSLV2 | SYSCFG_CCCSR_HSLV3));
  728. #endif /* SYSCFG_CCCSR_HSLV */
  729. }
  730. /**
  731. * @brief Code selection for the I/O Compensation cell
  732. * @param SYSCFG_CompCode: Selects the code to be applied for the I/O compensation cell
  733. * This parameter can be one of the following values:
  734. * @arg SYSCFG_CELL_CODE : Select Code from the cell (available in the SYSCFG_CCVR)
  735. * @arg SYSCFG_REGISTER_CODE: Select Code from the SYSCFG compensation cell code register (SYSCFG_CCCR)
  736. * @retval None
  737. */
  738. void HAL_SYSCFG_CompensationCodeSelect(uint32_t SYSCFG_CompCode)
  739. {
  740. /* Check the parameter */
  741. assert_param(IS_SYSCFG_CODE_SELECT(SYSCFG_CompCode));
  742. MODIFY_REG(SYSCFG->CCCSR, SYSCFG_CCCSR_CS, (uint32_t)(SYSCFG_CompCode));
  743. }
  744. /**
  745. * @brief Code selection for the I/O Compensation cell
  746. * @param SYSCFG_PMOSCode: PMOS compensation code
  747. * This code is applied to the I/O compensation cell when the CS bit of the
  748. * SYSCFG_CMPCR is set
  749. * @param SYSCFG_NMOSCode: NMOS compensation code
  750. * This code is applied to the I/O compensation cell when the CS bit of the
  751. * SYSCFG_CMPCR is set
  752. * @retval None
  753. */
  754. void HAL_SYSCFG_CompensationCodeConfig(uint32_t SYSCFG_PMOSCode, uint32_t SYSCFG_NMOSCode )
  755. {
  756. /* Check the parameter */
  757. assert_param(IS_SYSCFG_CODE_CONFIG(SYSCFG_PMOSCode));
  758. assert_param(IS_SYSCFG_CODE_CONFIG(SYSCFG_NMOSCode));
  759. MODIFY_REG(SYSCFG->CCCR, SYSCFG_CCCR_NCC|SYSCFG_CCCR_PCC, (((uint32_t)(SYSCFG_PMOSCode)<< 4)|(uint32_t)(SYSCFG_NMOSCode)) );
  760. }
  761. #if defined(SYSCFG_CCCR_NCC_MMC)
  762. /**
  763. * @brief Code selection for the I/O Compensation cell
  764. * @param SYSCFG_PMOSCode: VDDMMC PMOS compensation code
  765. * This code is applied to the I/O compensation cell when the CS bit of the
  766. * SYSCFG_CMPCR is set
  767. * @param SYSCFG_NMOSCode: VDDMMC NMOS compensation code
  768. * This code is applied to the I/O compensation cell when the CS bit of the
  769. * SYSCFG_CMPCR is set
  770. * @retval None
  771. */
  772. void HAL_SYSCFG_VDDMMC_CompensationCodeConfig(uint32_t SYSCFG_PMOSCode, uint32_t SYSCFG_NMOSCode )
  773. {
  774. /* Check the parameter */
  775. assert_param(IS_SYSCFG_CODE_CONFIG(SYSCFG_PMOSCode));
  776. assert_param(IS_SYSCFG_CODE_CONFIG(SYSCFG_NMOSCode));
  777. MODIFY_REG(SYSCFG->CCCR, (SYSCFG_CCCR_NCC_MMC | SYSCFG_CCCR_PCC_MMC), (((uint32_t)(SYSCFG_PMOSCode)<< 4)|(uint32_t)(SYSCFG_NMOSCode)) );
  778. }
  779. #endif /* SYSCFG_CCCR_NCC_MMC */
  780. #if defined(SYSCFG_ADC2ALT_ADC2_ROUT0)
  781. /** @brief SYSCFG ADC2 internal input alternate connection macros
  782. * @param Adc2AltRout0 This parameter can be a value of :
  783. * @arg @ref SYSCFG_ADC2_ROUT0_DAC1_1 DAC1_out1 connected to ADC2 VINP[16]
  784. * @arg @ref SYSCFG_ADC2_ROUT0_VBAT4 VBAT/4 connected to ADC2 VINP[16]
  785. */
  786. void HAL_SYSCFG_ADC2ALT_Rout0Config(uint32_t Adc2AltRout0)
  787. {
  788. /* Check the parameters */
  789. assert_param(IS_SYSCFG_ADC2ALT_ROUT0(Adc2AltRout0));
  790. MODIFY_REG(SYSCFG->ADC2ALT, SYSCFG_ADC2ALT_ADC2_ROUT0, Adc2AltRout0);
  791. }
  792. #endif /*SYSCFG_ADC2ALT_ADC2_ROUT0*/
  793. #if defined(SYSCFG_ADC2ALT_ADC2_ROUT1)
  794. /** @brief SYSCFG ADC2 internal input alternate connection macros
  795. * @param Adc2AltRout1 This parameter can be a value of :
  796. * @arg @ref SYSCFG_ADC2_ROUT1_DAC1_2 DAC1_out2 connected to ADC2 VINP[17]
  797. * @arg @ref SYSCFG_ADC2_ROUT1_VREFINT VREFINT connected to ADC2 VINP[17]
  798. */
  799. void HAL_SYSCFG_ADC2ALT_Rout1Config(uint32_t Adc2AltRout1)
  800. {
  801. /* Check the parameters */
  802. assert_param(IS_SYSCFG_ADC2ALT_ROUT1(Adc2AltRout1));
  803. MODIFY_REG(SYSCFG->ADC2ALT, SYSCFG_ADC2ALT_ADC2_ROUT1, Adc2AltRout1);
  804. }
  805. #endif /*SYSCFG_ADC2ALT_ADC2_ROUT1*/
  806. /**
  807. * @brief Enable the Debug Module during Domain1/CDomain SLEEP mode
  808. * @retval None
  809. */
  810. void HAL_DBGMCU_EnableDBGSleepMode(void)
  811. {
  812. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEPD1);
  813. }
  814. /**
  815. * @brief Disable the Debug Module during Domain1/CDomain SLEEP mode
  816. * @retval None
  817. */
  818. void HAL_DBGMCU_DisableDBGSleepMode(void)
  819. {
  820. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEPD1);
  821. }
  822. /**
  823. * @brief Enable the Debug Module during Domain1/CDomain STOP mode
  824. * @retval None
  825. */
  826. void HAL_DBGMCU_EnableDBGStopMode(void)
  827. {
  828. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOPD1);
  829. }
  830. /**
  831. * @brief Disable the Debug Module during Domain1/CDomain STOP mode
  832. * @retval None
  833. */
  834. void HAL_DBGMCU_DisableDBGStopMode(void)
  835. {
  836. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOPD1);
  837. }
  838. /**
  839. * @brief Enable the Debug Module during Domain1/CDomain STANDBY mode
  840. * @retval None
  841. */
  842. void HAL_DBGMCU_EnableDBGStandbyMode(void)
  843. {
  844. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBYD1);
  845. }
  846. /**
  847. * @brief Disable the Debug Module during Domain1/CDomain STANDBY mode
  848. * @retval None
  849. */
  850. void HAL_DBGMCU_DisableDBGStandbyMode(void)
  851. {
  852. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBYD1);
  853. }
  854. #if defined(DUAL_CORE)
  855. /**
  856. * @brief Enable the Debug Module during Domain1 SLEEP mode
  857. * @retval None
  858. */
  859. void HAL_EnableDomain2DBGSleepMode(void)
  860. {
  861. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEPD2);
  862. }
  863. /**
  864. * @brief Disable the Debug Module during Domain2 SLEEP mode
  865. * @retval None
  866. */
  867. void HAL_DisableDomain2DBGSleepMode(void)
  868. {
  869. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_SLEEPD2);
  870. }
  871. /**
  872. * @brief Enable the Debug Module during Domain2 STOP mode
  873. * @retval None
  874. */
  875. void HAL_EnableDomain2DBGStopMode(void)
  876. {
  877. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOPD2);
  878. }
  879. /**
  880. * @brief Disable the Debug Module during Domain2 STOP mode
  881. * @retval None
  882. */
  883. void HAL_DisableDomain2DBGStopMode(void)
  884. {
  885. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOPD2);
  886. }
  887. /**
  888. * @brief Enable the Debug Module during Domain2 STANDBY mode
  889. * @retval None
  890. */
  891. void HAL_EnableDomain2DBGStandbyMode(void)
  892. {
  893. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBYD2);
  894. }
  895. /**
  896. * @brief Disable the Debug Module during Domain2 STANDBY mode
  897. * @retval None
  898. */
  899. void HAL_DisableDomain2DBGStandbyMode(void)
  900. {
  901. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBYD2);
  902. }
  903. #endif /*DUAL_CORE*/
  904. #if defined(DBGMCU_CR_DBG_STOPD3)
  905. /**
  906. * @brief Enable the Debug Module during Domain3/SRDomain STOP mode
  907. * @retval None
  908. */
  909. void HAL_EnableDomain3DBGStopMode(void)
  910. {
  911. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOPD3);
  912. }
  913. /**
  914. * @brief Disable the Debug Module during Domain3/SRDomain STOP mode
  915. * @retval None
  916. */
  917. void HAL_DisableDomain3DBGStopMode(void)
  918. {
  919. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STOPD3);
  920. }
  921. #endif /*DBGMCU_CR_DBG_STOPD3*/
  922. #if defined(DBGMCU_CR_DBG_STANDBYD3)
  923. /**
  924. * @brief Enable the Debug Module during Domain3/SRDomain STANDBY mode
  925. * @retval None
  926. */
  927. void HAL_EnableDomain3DBGStandbyMode(void)
  928. {
  929. SET_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBYD3);
  930. }
  931. /**
  932. * @brief Disable the Debug Module during Domain3/SRDomain STANDBY mode
  933. * @retval None
  934. */
  935. void HAL_DisableDomain3DBGStandbyMode(void)
  936. {
  937. CLEAR_BIT(DBGMCU->CR, DBGMCU_CR_DBG_STANDBYD3);
  938. }
  939. #endif /*DBGMCU_CR_DBG_STANDBYD3*/
  940. /**
  941. * @brief Set the FMC Memory Mapping Swapping config.
  942. * @param BankMapConfig: Defines the FMC Bank mapping configuration. This parameter can be
  943. FMC_SWAPBMAP_DISABLE, FMC_SWAPBMAP_SDRAM_SRAM, FMC_SWAPBMAP_SDRAMB2
  944. * @retval HAL state
  945. */
  946. void HAL_SetFMCMemorySwappingConfig(uint32_t BankMapConfig)
  947. {
  948. /* Check the parameter */
  949. assert_param(IS_FMC_SWAPBMAP_MODE(BankMapConfig));
  950. MODIFY_REG(FMC_Bank1_R->BTCR[0], FMC_BCR1_BMAP, BankMapConfig);
  951. }
  952. /**
  953. * @brief Get FMC Bank mapping mode.
  954. * @retval The FMC Bank mapping mode. This parameter can be
  955. FMC_SWAPBMAP_DISABLE, FMC_SWAPBMAP_SDRAM_SRAM, FMC_SWAPBMAP_SDRAMB2
  956. */
  957. uint32_t HAL_GetFMCMemorySwappingConfig(void)
  958. {
  959. return READ_BIT(FMC_Bank1_R->BTCR[0], FMC_BCR1_BMAP);
  960. }
  961. /**
  962. * @brief Configure the EXTI input event line edge
  963. * @note No edge configuration for direct lines but for configurable lines:(EXTI_LINE0..EXTI_LINE21),
  964. * EXTI_LINE49,EXTI_LINE51,EXTI_LINE82,EXTI_LINE84,EXTI_LINE85 and EXTI_LINE86.
  965. * @param EXTI_Line: Specifies the EXTI LINE, it can be one of the following values,
  966. * (EXTI_LINE0....EXTI_LINE87)excluding :line45, line81,line83 which are reserved
  967. * @param EXTI_Edge: Specifies EXTI line Edge used.
  968. * This parameter can be one of the following values :
  969. * @arg EXTI_RISING_EDGE : Configurable line, with Rising edge trigger detection
  970. * @arg EXTI_FALLING_EDGE: Configurable line, with Falling edge trigger detection
  971. * @retval None
  972. */
  973. void HAL_EXTI_EdgeConfig(uint32_t EXTI_Line , uint32_t EXTI_Edge )
  974. {
  975. /* Check the parameter */
  976. assert_param(IS_HAL_EXTI_CONFIG_LINE(EXTI_Line));
  977. assert_param(IS_EXTI_EDGE_LINE(EXTI_Edge));
  978. /* Clear Rising Falling edge configuration */
  979. CLEAR_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI->FTSR1)) + ((EXTI_Line >> 5 ) * 0x20UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  980. CLEAR_BIT( *(__IO uint32_t *) (((uint32_t) &(EXTI->RTSR1)) + ((EXTI_Line >> 5 ) * 0x20UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  981. if( (EXTI_Edge & EXTI_RISING_EDGE) == EXTI_RISING_EDGE)
  982. {
  983. SET_BIT( *(__IO uint32_t *) (((uint32_t) &(EXTI->RTSR1)) + ((EXTI_Line >> 5 ) * 0x20UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  984. }
  985. if( (EXTI_Edge & EXTI_FALLING_EDGE) == EXTI_FALLING_EDGE)
  986. {
  987. SET_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI->FTSR1)) + ((EXTI_Line >> 5 ) * 0x20UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  988. }
  989. }
  990. /**
  991. * @brief Generates a Software interrupt on selected EXTI line.
  992. * @param EXTI_Line: Specifies the EXTI LINE, it can be one of the following values,
  993. * (EXTI_LINE0..EXTI_LINE21),EXTI_LINE49,EXTI_LINE51,EXTI_LINE82,EXTI_LINE84,EXTI_LINE85 and EXTI_LINE86.
  994. * @retval None
  995. */
  996. void HAL_EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
  997. {
  998. /* Check the parameters */
  999. assert_param(IS_HAL_EXTI_CONFIG_LINE(EXTI_Line));
  1000. SET_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI->SWIER1)) + ((EXTI_Line >> 5 ) * 0x20UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  1001. }
  1002. /**
  1003. * @brief Clears the EXTI's line pending flags for Domain D1
  1004. * @param EXTI_Line: Specifies the EXTI LINE, it can be one of the following values,
  1005. * (EXTI_LINE0....EXTI_LINE87)excluding :line45, line81,line83 which are reserved
  1006. * @retval None
  1007. */
  1008. void HAL_EXTI_D1_ClearFlag(uint32_t EXTI_Line)
  1009. {
  1010. /* Check the parameters */
  1011. assert_param(IS_EXTI_D1_LINE(EXTI_Line));
  1012. WRITE_REG(*(__IO uint32_t *) (((uint32_t) &(EXTI_D1->PR1)) + ((EXTI_Line >> 5 ) * 0x10UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  1013. }
  1014. #if defined(DUAL_CORE)
  1015. /**
  1016. * @brief Clears the EXTI's line pending flags for Domain D2
  1017. * @param EXTI_Line: Specifies the EXTI LINE, it can be one of the following values,
  1018. * (EXTI_LINE0....EXTI_LINE87)excluding :line45, line81,line83 which are reserved
  1019. * @retval None
  1020. */
  1021. void HAL_EXTI_D2_ClearFlag(uint32_t EXTI_Line)
  1022. {
  1023. /* Check the parameters */
  1024. assert_param(IS_EXTI_D2_LINE(EXTI_Line));
  1025. WRITE_REG(*(__IO uint32_t *) (((uint32_t) &(EXTI_D2->PR1)) + ((EXTI_Line >> 5 ) * 0x10UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  1026. }
  1027. #endif /*DUAL_CORE*/
  1028. /**
  1029. * @brief Configure the EXTI input event line for Domain D1
  1030. * @param EXTI_Line: Specifies the EXTI LINE, it can be one of the following values,
  1031. * (EXTI_LINE0....EXTI_LINE87)excluding :line45, line81,line83 which are reserved
  1032. * @param EXTI_Mode: Specifies which EXTI line is used as interrupt or an event.
  1033. * This parameter can be one or a combination of the following values :
  1034. * @arg EXTI_MODE_IT : Interrupt Mode selected
  1035. * @arg EXTI_MODE_EVT : Event Mode selected
  1036. * @param EXTI_LineCmd controls (Enable/Disable) the EXTI line.
  1037. * @retval None
  1038. */
  1039. void HAL_EXTI_D1_EventInputConfig(uint32_t EXTI_Line , uint32_t EXTI_Mode, uint32_t EXTI_LineCmd )
  1040. {
  1041. /* Check the parameter */
  1042. assert_param(IS_EXTI_D1_LINE(EXTI_Line));
  1043. assert_param(IS_EXTI_MODE_LINE(EXTI_Mode));
  1044. if( (EXTI_Mode & EXTI_MODE_IT) == EXTI_MODE_IT)
  1045. {
  1046. if( EXTI_LineCmd == 0UL)
  1047. {
  1048. /* Clear EXTI line configuration */
  1049. CLEAR_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI_D1->IMR1)) + ((EXTI_Line >> 5 ) * 0x10UL)),(uint32_t)(1UL << (EXTI_Line & 0x1FUL)) );
  1050. }
  1051. else
  1052. {
  1053. SET_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI_D1->IMR1)) + ((EXTI_Line >> 5 ) * 0x10UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  1054. }
  1055. }
  1056. if( (EXTI_Mode & EXTI_MODE_EVT) == EXTI_MODE_EVT)
  1057. {
  1058. if( EXTI_LineCmd == 0UL)
  1059. {
  1060. /* Clear EXTI line configuration */
  1061. CLEAR_BIT( *(__IO uint32_t *) (((uint32_t) &(EXTI_D1->EMR1)) + ((EXTI_Line >> 5 ) * 0x10UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  1062. }
  1063. else
  1064. {
  1065. SET_BIT( *(__IO uint32_t *) (((uint32_t) &(EXTI_D1->EMR1)) + ((EXTI_Line >> 5 ) * 0x10UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  1066. }
  1067. }
  1068. }
  1069. #if defined(DUAL_CORE)
  1070. /**
  1071. * @brief Configure the EXTI input event line for Domain D2
  1072. * @param EXTI_Line: Specifies the EXTI LINE, it can be one of the following values,
  1073. * (EXTI_LINE0....EXTI_LINE87)excluding :line45, line81,line83 which are reserved
  1074. * @param EXTI_Mode: Specifies which EXTI line is used as interrupt or an event.
  1075. * This parameter can be one or a combination of the following values :
  1076. * @arg EXTI_MODE_IT : Interrupt Mode selected
  1077. * @arg EXTI_MODE_EVT : Event Mode selected
  1078. * @param EXTI_LineCmd controls (Enable/Disable) the EXTI line.
  1079. * @retval None
  1080. */
  1081. void HAL_EXTI_D2_EventInputConfig(uint32_t EXTI_Line , uint32_t EXTI_Mode, uint32_t EXTI_LineCmd )
  1082. {
  1083. /* Check the parameter */
  1084. assert_param(IS_EXTI_D2_LINE(EXTI_Line));
  1085. assert_param(IS_EXTI_MODE_LINE(EXTI_Mode));
  1086. if( (EXTI_Mode & EXTI_MODE_IT) == EXTI_MODE_IT)
  1087. {
  1088. if( EXTI_LineCmd == 0UL)
  1089. {
  1090. /* Clear EXTI line configuration */
  1091. CLEAR_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI_D2->IMR1)) + ((EXTI_Line >> 5 ) * 0x10UL)),(uint32_t)(1UL << (EXTI_Line & 0x1FUL)) );
  1092. }
  1093. else
  1094. {
  1095. SET_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI_D2->IMR1)) + ((EXTI_Line >> 5 ) * 0x10UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  1096. }
  1097. }
  1098. if( (EXTI_Mode & EXTI_MODE_EVT) == EXTI_MODE_EVT)
  1099. {
  1100. if( EXTI_LineCmd == 0UL)
  1101. {
  1102. /* Clear EXTI line configuration */
  1103. CLEAR_BIT( *(__IO uint32_t *) (((uint32_t) &(EXTI_D2->EMR1)) + ((EXTI_Line >> 5 ) * 0x10UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  1104. }
  1105. else
  1106. {
  1107. SET_BIT( *(__IO uint32_t *) (((uint32_t) &(EXTI_D2->EMR1)) + ((EXTI_Line >> 5 ) * 0x10UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  1108. }
  1109. }
  1110. }
  1111. #endif /*DUAL_CORE*/
  1112. /**
  1113. * @brief Configure the EXTI input event line for Domain D3
  1114. * @param EXTI_Line: Specifies the EXTI LINE, it can be one of the following values,
  1115. * (EXTI_LINE0...EXTI_LINE15),(EXTI_LINE19...EXTI_LINE21),EXTI_LINE25, EXTI_LINE34,
  1116. * EXTI_LINE35,EXTI_LINE41,(EXTI_LINE48...EXTI_LINE53)
  1117. * @param EXTI_LineCmd controls (Enable/Disable) the EXTI line.
  1118. * @param EXTI_ClearSrc: Specifies the clear source of D3 pending event.
  1119. * This parameter can be one of the following values :
  1120. * @arg BDMA_CH6_CLEAR : BDMA ch6 event selected as D3 domain pendclear source
  1121. * @arg BDMA_CH7_CLEAR : BDMA ch7 event selected as D3 domain pendclear source
  1122. * @arg LPTIM4_OUT_CLEAR : LPTIM4 out selected as D3 domain pendclear source
  1123. * @arg LPTIM5_OUT_CLEAR : LPTIM5 out selected as D3 domain pendclear source
  1124. * @retval None
  1125. */
  1126. void HAL_EXTI_D3_EventInputConfig(uint32_t EXTI_Line, uint32_t EXTI_LineCmd , uint32_t EXTI_ClearSrc )
  1127. {
  1128. __IO uint32_t *pRegv;
  1129. /* Check the parameter */
  1130. assert_param(IS_EXTI_D3_LINE(EXTI_Line));
  1131. assert_param(IS_EXTI_D3_CLEAR(EXTI_ClearSrc));
  1132. if( EXTI_LineCmd == 0UL)
  1133. {
  1134. /* Clear EXTI line configuration */
  1135. CLEAR_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI->D3PMR1)) + ((EXTI_Line >> 5 ) * 0x20UL)),(uint32_t)(1UL << (EXTI_Line & 0x1FUL)) );
  1136. }
  1137. else
  1138. {
  1139. SET_BIT(*(__IO uint32_t *) (((uint32_t) &(EXTI->D3PMR1)) +((EXTI_Line >> 5 ) * 0x20UL)), (uint32_t)(1UL << (EXTI_Line & 0x1FUL)));
  1140. }
  1141. if(((EXTI_Line>>4)%2UL) == 0UL)
  1142. {
  1143. pRegv = (__IO uint32_t *) (((uint32_t) &(EXTI->D3PCR1L)) + ((EXTI_Line >> 5 ) * 0x20UL));
  1144. }
  1145. else
  1146. {
  1147. pRegv = (__IO uint32_t *) (((uint32_t) &(EXTI->D3PCR1H)) + ((EXTI_Line >> 5 ) * 0x20UL));
  1148. }
  1149. MODIFY_REG(*pRegv, (uint32_t)(3UL << ((EXTI_Line*2UL) & 0x1FUL)), (uint32_t)(EXTI_ClearSrc << ((EXTI_Line*2UL) & 0x1FUL)));
  1150. }
  1151. /**
  1152. * @}
  1153. */
  1154. /**
  1155. * @}
  1156. */
  1157. /**
  1158. * @}
  1159. */
  1160. /**
  1161. * @}
  1162. */