stm32h7xx_ll_utils.h 17 KB

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