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

382 lines
14 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_ll_utils.h
  4. * @author MCD Application Team
  5. * @brief Header file of UTILS LL module.
  6. @verbatim
  7. ==============================================================================
  8. ##### How to use this driver #####
  9. ==============================================================================
  10. [..]
  11. The LL UTILS driver contains a set of generic APIs that can be
  12. used by user:
  13. (+) Device electronic signature
  14. (+) Timing functions
  15. (+) PLL configuration functions
  16. @endverbatim
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. /* Define to prevent recursive inclusion -------------------------------------*/
  31. #ifndef STM32H7xx_LL_UTILS_H
  32. #define STM32H7xx_LL_UTILS_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "stm32h7xx.h"
  38. #include "stm32h7xx_ll_system.h"
  39. #include "stm32h7xx_ll_bus.h"
  40. /** @addtogroup STM32H7xx_LL_Driver
  41. * @{
  42. */
  43. /** @defgroup UTILS_LL UTILS
  44. * @{
  45. */
  46. /* Private types -------------------------------------------------------------*/
  47. /* Private variables ---------------------------------------------------------*/
  48. /* Private constants ---------------------------------------------------------*/
  49. /** @defgroup UTILS_LL_Private_Constants UTILS Private Constants
  50. * @{
  51. */
  52. /* Max delay can be used in LL_mDelay */
  53. #define LL_MAX_DELAY 0xFFFFFFFFU
  54. /**
  55. * @brief Unique device ID register base address
  56. */
  57. #define UID_BASE_ADDRESS UID_BASE
  58. /**
  59. * @brief Flash size data register base address
  60. */
  61. #define FLASHSIZE_BASE_ADDRESS FLASHSIZE_BASE
  62. /**
  63. * @brief Package data register base address
  64. */
  65. #define PACKAGE_BASE_ADDRESS PACKAGE_BASE
  66. /**
  67. * @}
  68. */
  69. /* Private macros ------------------------------------------------------------*/
  70. /** @defgroup UTILS_LL_Private_Macros UTILS Private Macros
  71. * @{
  72. */
  73. /**
  74. * @}
  75. */
  76. /* Exported types ------------------------------------------------------------*/
  77. /** @defgroup UTILS_LL_ES_INIT UTILS Exported structures
  78. * @{
  79. */
  80. /**
  81. * @brief UTILS PLL structure definition
  82. */
  83. typedef struct
  84. {
  85. uint32_t PLLM; /*!< Division factor for PLL VCO input clock.
  86. This parameter must be a number between Min_Data = 0 and Max_Data = 63
  87. This feature can be modified afterwards using unitary function
  88. @ref LL_RCC_PLL1_SetM(). */
  89. uint32_t PLLN; /*!< Multiplication factor for PLL VCO output clock.
  90. This parameter must be a number between Min_Data = 4 and Max_Data = 512
  91. This feature can be modified afterwards using unitary function
  92. @ref LL_RCC_PLL1_SetN(). */
  93. uint32_t PLLP; /*!< Division for the main system clock.
  94. This parameter must be a number between Min_Data = 2 and Max_Data = 128
  95. odd division factors are not allowed
  96. This feature can be modified afterwards using unitary function
  97. @ref LL_RCC_PLL1_SetP(). */
  98. uint32_t FRACN; /*!< Fractional part of the multiplication factor for PLL VCO.
  99. This parameter can be a value between 0 and 8191
  100. This feature can be modified afterwards using unitary function
  101. @ref LL_RCC_PLL1_SetFRACN(). */
  102. uint32_t VCO_Input; /*!< Fractional part of the multiplication factor for PLL VCO.
  103. This parameter can be a value of @ref RCC_LL_EC_PLLINPUTRANGE
  104. This feature can be modified afterwards using unitary function
  105. @ref LL_RCC_PLL1_SetVCOInputRange(). */
  106. uint32_t VCO_Output; /*!< Fractional part of the multiplication factor for PLL VCO.
  107. This parameter can be a value of @ref RCC_LL_EC_PLLVCORANGE
  108. This feature can be modified afterwards using unitary function
  109. @ref LL_RCC_PLL1_SetVCOOutputRange(). */
  110. } LL_UTILS_PLLInitTypeDef;
  111. /**
  112. * @brief UTILS System, AHB and APB buses clock configuration structure definition
  113. */
  114. typedef struct
  115. {
  116. uint32_t SYSCLKDivider; /*!< The System clock (SYSCLK) divider. This clock is derived from the PLL output.
  117. This parameter can be a value of @ref RCC_LL_EC_SYSCLK_DIV
  118. This feature can be modified afterwards using unitary function
  119. @ref LL_RCC_SetSysPrescaler(). */
  120. uint32_t AHBCLKDivider; /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
  121. This parameter can be a value of @ref RCC_LL_EC_AHB_DIV
  122. This feature can be modified afterwards using unitary function
  123. @ref LL_RCC_SetAHBPrescaler(). */
  124. uint32_t APB1CLKDivider; /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
  125. This parameter can be a value of @ref RCC_LL_EC_APB1_DIV
  126. This feature can be modified afterwards using unitary function
  127. @ref LL_RCC_SetAPB1Prescaler(). */
  128. uint32_t APB2CLKDivider; /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
  129. This parameter can be a value of @ref RCC_LL_EC_APB2_DIV
  130. This feature can be modified afterwards using unitary function
  131. @ref LL_RCC_SetAPB2Prescaler(). */
  132. uint32_t APB3CLKDivider; /*!< The APB2 clock (PCLK3) divider. This clock is derived from the AHB clock (HCLK).
  133. This parameter can be a value of @ref RCC_LL_EC_APB3_DIV
  134. This feature can be modified afterwards using unitary function
  135. @ref LL_RCC_SetAPB3Prescaler(). */
  136. uint32_t APB4CLKDivider; /*!< The APB4 clock (PCLK4) divider. This clock is derived from the AHB clock (HCLK).
  137. This parameter can be a value of @ref RCC_LL_EC_APB4_DIV
  138. This feature can be modified afterwards using unitary function
  139. @ref LL_RCC_SetAPB4Prescaler(). */
  140. } LL_UTILS_ClkInitTypeDef;
  141. /**
  142. * @}
  143. */
  144. /* Exported constants --------------------------------------------------------*/
  145. /** @defgroup UTILS_LL_Exported_Constants UTILS Exported Constants
  146. * @{
  147. */
  148. /** @defgroup UTILS_EC_HSE_BYPASS HSE Bypass activation
  149. * @{
  150. */
  151. #define LL_UTILS_HSEBYPASS_OFF 0x00000000U /*!< HSE Bypass is not enabled */
  152. #define LL_UTILS_HSEBYPASS_ON 0x00000001U /*!< HSE Bypass is enabled */
  153. /**
  154. * @}
  155. */
  156. /** @defgroup UTILS_EC_PACKAGETYPE PACKAGE TYPE
  157. * @{
  158. */
  159. #if defined(SYSCFG_PKGR_PKG)
  160. #define LL_UTILS_PACKAGETYPE_LQFP100 LL_SYSCFG_LQFP100_PACKAGE /*!< LQFP100 package type */
  161. #define LL_UTILS_PACKAGETYPE_TQFP144 LL_SYSCFG_TQFP144_PACKAGE /*!< TQFP144 package type */
  162. #define LL_UTILS_PACKAGETYPE_TQFP176_UFBGA176 LL_SYSCFG_TQFP176_UFBGA176_PACKAGE /*!< TQFP176 or UFBGA176 package type */
  163. #define LL_UTILS_PACKAGETYPE_LQFP208_TFBGA240 LL_SYSCFG_LQFP208_TFBGA240_PACKAGE /*!< LQFP208 or TFBGA240 package type */
  164. #else
  165. #define LL_UTILS_PACKAGETYPE_LQFP64 0x00000000UL /*!< LQFP64 package type */
  166. #define LL_UTILS_PACKAGETYPE_TFBGA100_LQFP100 0x00000001UL /*!< TFBGA100 or LQFP100 package type */
  167. #define LL_UTILS_PACKAGETYPE_LQFP100_SMPS 0x00000002UL /*!< LQFP100 with SMPS package type */
  168. #define LL_UTILS_PACKAGETYPE_TFBGA100_SMPS 0x00000003UL /*!< TFBGA100 with SMPS package type */
  169. #define LL_UTILS_PACKAGETYPE_WLCSP132_SMPS 0x00000004UL /*!< WLCSP132 package type */
  170. #define LL_UTILS_PACKAGETYPE_LQFP144 0x00000005UL /*!< LQFP144 package type */
  171. #define LL_UTILS_PACKAGETYPE_LQFP144_SMPS 0x00000006UL /*!< LQFP144 with SMPS package type */
  172. #define LL_UTILS_PACKAGETYPE_UFBGA169 0x00000007UL /*!< UFBGA169 package type */
  173. #define LL_UTILS_PACKAGETYPE_UFBGA176_LQFP176 0x00000010UL /*!< UFBGA176 or LQFP176 package type */
  174. #define LL_UTILS_PACKAGETYPE_LQFP176_SMPS 0x00000011UL /*!< LQFP176 with SMPS package type */
  175. #define LL_UTILS_PACKAGETYPE_UFBGA176_SMPS 0x00000012UL /*!< UFBGA176 with SMPS package type */
  176. #define LL_UTILS_PACKAGETYPE_TFBGA216 0x00000014UL /*!< TFBGA216 package type */
  177. #define LL_UTILS_PACKAGETYPE_TFBGA225 0x00000016UL /*!< TFBGA225 package type */
  178. #endif /* SYSCFG_PKGR_PKG */
  179. /**
  180. * @}
  181. */
  182. /**
  183. * @}
  184. */
  185. /* Exported macro ------------------------------------------------------------*/
  186. /* Exported functions --------------------------------------------------------*/
  187. /** @defgroup UTILS_LL_Exported_Functions UTILS Exported Functions
  188. * @{
  189. */
  190. /** @defgroup UTILS_EF_DEVICE_ELECTRONIC_SIGNATURE DEVICE ELECTRONIC SIGNATURE
  191. * @{
  192. */
  193. /**
  194. * @brief Get Word0 of the unique device identifier (UID based on 96 bits)
  195. * @retval UID[31:0]
  196. */
  197. __STATIC_INLINE uint32_t LL_GetUID_Word0(void)
  198. {
  199. return (uint32_t)(READ_REG(*((uint32_t *)UID_BASE_ADDRESS)));
  200. }
  201. /**
  202. * @brief Get Word1 of the unique device identifier (UID based on 96 bits)
  203. * @retval UID[63:32]
  204. */
  205. __STATIC_INLINE uint32_t LL_GetUID_Word1(void)
  206. {
  207. return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 4U))));
  208. }
  209. /**
  210. * @brief Get Word2 of the unique device identifier (UID based on 96 bits)
  211. * @retval UID[95:64]
  212. */
  213. __STATIC_INLINE uint32_t LL_GetUID_Word2(void)
  214. {
  215. return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 8U))));
  216. }
  217. /**
  218. * @brief Get Flash memory size
  219. * @note This bitfield indicates the size of the device Flash memory expressed in
  220. * Kbytes. As an example, 0x040 corresponds to 64 Kbytes.
  221. * @retval FLASH_SIZE[15:0]: Flash memory size
  222. */
  223. __STATIC_INLINE uint32_t LL_GetFlashSize(void)
  224. {
  225. return (uint16_t)(READ_REG(*((uint32_t *)FLASHSIZE_BASE_ADDRESS)));
  226. }
  227. /**
  228. * @brief Get Package type
  229. * @retval Returned value can be one of the following values:
  230. * @arg @ref LL_UTILS_PACKAGETYPE_LQFP100
  231. * @arg @ref LL_UTILS_PACKAGETYPE_TQFP144
  232. * @arg @ref LL_UTILS_PACKAGETYPE_TQFP176_UFBGA176
  233. * @arg @ref LL_UTILS_PACKAGETYPE_LQFP208_TFBGA240
  234. * @arg @ref LL_UTILS_PACKAGETYPE_LQFP64 (*)
  235. * @arg @ref LL_UTILS_PACKAGETYPE_TFBGA100_LQFP100 (*)
  236. * @arg @ref LL_UTILS_PACKAGETYPE_LQFP100_SMPS (*)
  237. * @arg @ref LL_UTILS_PACKAGETYPE_TFBGA100_SMPS (*)
  238. * @arg @ref LL_UTILS_PACKAGETYPE_WLCSP132_SMPS (*)
  239. * @arg @ref LL_UTILS_PACKAGETYPE_LQFP144 (*)
  240. * @arg @ref LL_UTILS_PACKAGETYPE_LQFP144_SMPS (*)
  241. * @arg @ref LL_UTILS_PACKAGETYPE_UFBGA169 (*)
  242. * @arg @ref LL_UTILS_PACKAGETYPE_UFBGA176_LQFP176 (*)
  243. * @arg @ref LL_UTILS_PACKAGETYPE_LQFP176_SMPS (*)
  244. * @arg @ref LL_UTILS_PACKAGETYPE_UFBGA176_SMPS (*)
  245. * @arg @ref LL_UTILS_PACKAGETYPE_TFBGA216 (*)
  246. * @arg @ref LL_UTILS_PACKAGETYPE_TFBGA225 (*)
  247. *
  248. * (*) Packages available on some STM32H7 lines only.
  249. * @note For some SM32H7 lines, enabling the SYSCFG clock is mandatory.
  250. the SYSCFG clock enabling is ensured by LL_APB4_GRP1_EnableClock
  251. */
  252. __STATIC_INLINE uint32_t LL_GetPackageType(void)
  253. {
  254. #if defined(SYSCFG_PKGR_PKG)
  255. return LL_SYSCFG_GetPackage();
  256. #else
  257. return (uint16_t)(READ_REG(*((uint32_t *)PACKAGE_BASE_ADDRESS)));
  258. #endif /* SYSCFG_PKGR_PKG */
  259. }
  260. /**
  261. * @}
  262. */
  263. /** @defgroup UTILS_LL_EF_DELAY DELAY
  264. * @{
  265. */
  266. /**
  267. * @brief This function configures the Cortex-M SysTick source of the time base.
  268. * @param HCLKFrequency HCLK frequency in Hz (can be calculated thanks to RCC helper macro)
  269. * @note When a RTOS is used, it is recommended to avoid changing the SysTick
  270. * configuration by calling this function, for a delay use rather osDelay RTOS service.
  271. * @param Ticks Number of ticks
  272. * @retval None
  273. */
  274. __STATIC_INLINE void LL_InitTick(uint32_t HCLKFrequency, uint32_t Ticks)
  275. {
  276. /* Configure the SysTick to have interrupt in 1ms time base */
  277. SysTick->LOAD = (uint32_t)((HCLKFrequency / Ticks) - 1UL); /* set reload register */
  278. SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
  279. SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
  280. SysTick_CTRL_ENABLE_Msk; /* Enable the Systick Timer */
  281. }
  282. void LL_Init1msTick(uint32_t CPU_Frequency);
  283. void LL_mDelay(uint32_t Delay);
  284. /**
  285. * @}
  286. */
  287. /** @defgroup UTILS_EF_SYSTEM SYSTEM
  288. * @{
  289. */
  290. void LL_SetSystemCoreClock(uint32_t CPU_Frequency);
  291. ErrorStatus LL_PLL_ConfigSystemClock_HSI(LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct,
  292. LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct);
  293. ErrorStatus LL_PLL_ConfigSystemClock_HSE(uint32_t HSEFrequency,
  294. uint32_t HSEBypass,
  295. LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct,
  296. LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct);
  297. /**
  298. * @}
  299. */
  300. /**
  301. * @}
  302. */
  303. /**
  304. * @}
  305. */
  306. /**
  307. * @}
  308. */
  309. #ifdef __cplusplus
  310. }
  311. #endif
  312. #endif /* STM32H7xx_LL_UTILS_H */
  313. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/