STM32F479xx HAL User Manual
stm32f4xx_ll_utils.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_ll_utils.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of UTILS LL module.
00006   @verbatim
00007   ==============================================================================
00008                      ##### How to use this driver #####
00009   ==============================================================================
00010     [..]
00011     The LL UTILS driver contains a set of generic APIs that can be
00012     used by user:
00013       (+) Device electronic signature
00014       (+) Timing functions
00015       (+) PLL configuration functions
00016 
00017   @endverbatim
00018   ******************************************************************************
00019   * @attention
00020   *
00021   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
00022   * All rights reserved.</center></h2>
00023   *
00024   * This software component is licensed by ST under BSD 3-Clause license,
00025   * the "License"; You may not use this file except in compliance with the
00026   * License. You may obtain a copy of the License at:
00027   *                        opensource.org/licenses/BSD-3-Clause
00028   *
00029   ******************************************************************************
00030   */
00031 
00032 /* Define to prevent recursive inclusion -------------------------------------*/
00033 #ifndef __STM32F4xx_LL_UTILS_H
00034 #define __STM32F4xx_LL_UTILS_H
00035 
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039 
00040 /* Includes ------------------------------------------------------------------*/
00041 #include "stm32f4xx.h"
00042 
00043 /** @addtogroup STM32F4xx_LL_Driver
00044   * @{
00045   */
00046 
00047 /** @defgroup UTILS_LL UTILS
00048   * @{
00049   */
00050 
00051 /* Private types -------------------------------------------------------------*/
00052 /* Private variables ---------------------------------------------------------*/
00053 
00054 /* Private constants ---------------------------------------------------------*/
00055 /** @defgroup UTILS_LL_Private_Constants UTILS Private Constants
00056   * @{
00057   */
00058 
00059 /* Max delay can be used in LL_mDelay */
00060 #define LL_MAX_DELAY                  0xFFFFFFFFU
00061 
00062 /**
00063  * @brief Unique device ID register base address
00064  */
00065 #define UID_BASE_ADDRESS              UID_BASE
00066 
00067 /**
00068  * @brief Flash size data register base address
00069  */
00070 #define FLASHSIZE_BASE_ADDRESS        FLASHSIZE_BASE
00071 
00072 /**
00073  * @brief Package data register base address
00074  */
00075 #define PACKAGE_BASE_ADDRESS          PACKAGE_BASE
00076 
00077 /**
00078   * @}
00079   */
00080 
00081 /* Private macros ------------------------------------------------------------*/
00082 /** @defgroup UTILS_LL_Private_Macros UTILS Private Macros
00083   * @{
00084   */
00085 /**
00086   * @}
00087   */
00088 /* Exported types ------------------------------------------------------------*/
00089 /** @defgroup UTILS_LL_ES_INIT UTILS Exported structures
00090   * @{
00091   */
00092 /**
00093   * @brief  UTILS PLL structure definition
00094   */
00095 typedef struct
00096 {
00097   uint32_t PLLM;   /*!< Division factor for PLL VCO input clock.
00098                         This parameter can be a value of @ref RCC_LL_EC_PLLM_DIV
00099 
00100                         This feature can be modified afterwards using unitary function
00101                         @ref LL_RCC_PLL_ConfigDomain_SYS(). */
00102 
00103   uint32_t PLLN;   /*!< Multiplication factor for PLL VCO output clock.
00104                         This parameter must be a number between Min_Data = @ref RCC_PLLN_MIN_VALUE
00105                         and Max_Data = @ref RCC_PLLN_MIN_VALUE
00106 
00107                         This feature can be modified afterwards using unitary function
00108                         @ref LL_RCC_PLL_ConfigDomain_SYS(). */
00109 
00110   uint32_t PLLP;   /*!< Division for the main system clock.
00111                         This parameter can be a value of @ref RCC_LL_EC_PLLP_DIV
00112 
00113                         This feature can be modified afterwards using unitary function
00114                         @ref LL_RCC_PLL_ConfigDomain_SYS(). */
00115 } LL_UTILS_PLLInitTypeDef;
00116 
00117 /**
00118   * @brief  UTILS System, AHB and APB buses clock configuration structure definition
00119   */
00120 typedef struct
00121 {
00122   uint32_t AHBCLKDivider;         /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
00123                                        This parameter can be a value of @ref RCC_LL_EC_SYSCLK_DIV
00124 
00125                                        This feature can be modified afterwards using unitary function
00126                                        @ref LL_RCC_SetAHBPrescaler(). */
00127 
00128   uint32_t APB1CLKDivider;        /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
00129                                        This parameter can be a value of @ref RCC_LL_EC_APB1_DIV
00130 
00131                                        This feature can be modified afterwards using unitary function
00132                                        @ref LL_RCC_SetAPB1Prescaler(). */
00133 
00134   uint32_t APB2CLKDivider;        /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
00135                                        This parameter can be a value of @ref RCC_LL_EC_APB2_DIV
00136 
00137                                        This feature can be modified afterwards using unitary function
00138                                        @ref LL_RCC_SetAPB2Prescaler(). */
00139 
00140 } LL_UTILS_ClkInitTypeDef;
00141 
00142 /**
00143   * @}
00144   */
00145 
00146 /* Exported constants --------------------------------------------------------*/
00147 /** @defgroup UTILS_LL_Exported_Constants UTILS Exported Constants
00148   * @{
00149   */
00150 
00151 /** @defgroup UTILS_EC_HSE_BYPASS HSE Bypass activation
00152   * @{
00153   */
00154 #define LL_UTILS_HSEBYPASS_OFF        0x00000000U       /*!< HSE Bypass is not enabled                */
00155 #define LL_UTILS_HSEBYPASS_ON         0x00000001U       /*!< HSE Bypass is enabled                    */
00156 /**
00157   * @}
00158   */
00159 
00160 /** @defgroup UTILS_EC_PACKAGETYPE PACKAGE TYPE
00161   * @{
00162   */
00163 #define LL_UTILS_PACKAGETYPE_WLCSP36_UFQFPN48_LQFP64                        0x00000000U /*!< WLCSP36 or UFQFPN48 or LQFP64 package type                         */
00164 #define LL_UTILS_PACKAGETYPE_WLCSP168_FBGA169_LQFP100_LQFP64_UFQFPN48       0x00000100U /*!< WLCSP168 or FBGA169 or LQFP100 or LQFP64 or UFQFPN48 package type  */
00165 #define LL_UTILS_PACKAGETYPE_WLCSP64_WLCSP81_LQFP176_UFBGA176               0x00000200U /*!< WLCSP64 or WLCSP81 or LQFP176 or UFBGA176 package type             */
00166 #define LL_UTILS_PACKAGETYPE_LQFP144_UFBGA144_UFBGA144_UFBGA100             0x00000300U /*!< LQFP144 or UFBGA144 or UFBGA144 or UFBGA100 package type           */
00167 #define LL_UTILS_PACKAGETYPE_LQFP100_LQFP208_TFBGA216                       0x00000400U /*!< LQFP100 or LQFP208 or TFBGA216 package type                        */
00168 #define LL_UTILS_PACKAGETYPE_LQFP208_TFBGA216                               0x00000500U /*!< LQFP208 or TFBGA216 package type                                   */
00169 #define LL_UTILS_PACKAGETYPE_TQFP64_UFBGA144_LQFP144                        0x00000700U /*!< TQFP64 or UFBGA144 or LQFP144 package type                         */
00170 /**
00171   * @}
00172   */
00173 
00174 /**
00175   * @}
00176   */
00177 
00178 /* Exported macro ------------------------------------------------------------*/
00179 
00180 /* Exported functions --------------------------------------------------------*/
00181 /** @defgroup UTILS_LL_Exported_Functions UTILS Exported Functions
00182   * @{
00183   */
00184 
00185 /** @defgroup UTILS_EF_DEVICE_ELECTRONIC_SIGNATURE DEVICE ELECTRONIC SIGNATURE
00186   * @{
00187   */
00188 
00189 /**
00190   * @brief  Get Word0 of the unique device identifier (UID based on 96 bits)
00191   * @retval UID[31:0]
00192   */
00193 __STATIC_INLINE uint32_t LL_GetUID_Word0(void)
00194 {
00195   return (uint32_t)(READ_REG(*((uint32_t *)UID_BASE_ADDRESS)));
00196 }
00197 
00198 /**
00199   * @brief  Get Word1 of the unique device identifier (UID based on 96 bits)
00200   * @retval UID[63:32]
00201   */
00202 __STATIC_INLINE uint32_t LL_GetUID_Word1(void)
00203 {
00204   return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 4U))));
00205 }
00206 
00207 /**
00208   * @brief  Get Word2 of the unique device identifier (UID based on 96 bits)
00209   * @retval UID[95:64]
00210   */
00211 __STATIC_INLINE uint32_t LL_GetUID_Word2(void)
00212 {
00213   return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 8U))));
00214 }
00215 
00216 /**
00217   * @brief  Get Flash memory size
00218   * @note   This bitfield indicates the size of the device Flash memory expressed in
00219   *         Kbytes. As an example, 0x040 corresponds to 64 Kbytes.
00220   * @retval FLASH_SIZE[15:0]: Flash memory size
00221   */
00222 __STATIC_INLINE uint32_t LL_GetFlashSize(void)
00223 {
00224   return (uint32_t)(READ_REG(*((uint32_t *)FLASHSIZE_BASE_ADDRESS)) & 0xFFFF);
00225 }
00226 
00227 /**
00228   * @brief  Get Package type
00229   * @retval Returned value can be one of the following values:
00230   *         @arg @ref LL_UTILS_PACKAGETYPE_WLCSP36_UFQFPN48_LQFP64 (*)
00231   *         @arg @ref LL_UTILS_PACKAGETYPE_WLCSP168_FBGA169_LQFP100_LQFP64_UFQFPN48 (*)
00232   *         @arg @ref LL_UTILS_PACKAGETYPE_WLCSP64_WLCSP81_LQFP176_UFBGA176 (*)
00233   *         @arg @ref LL_UTILS_PACKAGETYPE_LQFP144_UFBGA144_UFBGA144_UFBGA100 (*)
00234   *         @arg @ref LL_UTILS_PACKAGETYPE_LQFP100_LQFP208_TFBGA216 (*)
00235   *         @arg @ref LL_UTILS_PACKAGETYPE_LQFP208_TFBGA216 (*)
00236   *         @arg @ref LL_UTILS_PACKAGETYPE_TQFP64_UFBGA144_LQFP144 (*)
00237   * 
00238   *         (*) value not defined in all devices.
00239   */
00240 __STATIC_INLINE uint32_t LL_GetPackageType(void)
00241 {
00242   return (uint32_t)(READ_REG(*((uint32_t *)PACKAGE_BASE_ADDRESS)) & 0x0700U);
00243 }
00244 
00245 /**
00246   * @}
00247   */
00248 
00249 /** @defgroup UTILS_LL_EF_DELAY DELAY
00250   * @{
00251   */
00252 
00253 /**
00254   * @brief  This function configures the Cortex-M SysTick source of the time base.
00255   * @param  HCLKFrequency HCLK frequency in Hz (can be calculated thanks to RCC helper macro)
00256   * @note   When a RTOS is used, it is recommended to avoid changing the SysTick
00257   *         configuration by calling this function, for a delay use rather osDelay RTOS service.
00258   * @param  Ticks Number of ticks
00259   * @retval None
00260   */
00261 __STATIC_INLINE void LL_InitTick(uint32_t HCLKFrequency, uint32_t Ticks)
00262 {
00263   /* Configure the SysTick to have interrupt in 1ms time base */
00264   SysTick->LOAD  = (uint32_t)((HCLKFrequency / Ticks) - 1UL);  /* set reload register */
00265   SysTick->VAL   = 0UL;                                       /* Load the SysTick Counter Value */
00266   SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
00267                    SysTick_CTRL_ENABLE_Msk;                   /* Enable the Systick Timer */
00268 }
00269 
00270 void        LL_Init1msTick(uint32_t HCLKFrequency);
00271 void        LL_mDelay(uint32_t Delay);
00272 
00273 /**
00274   * @}
00275   */
00276 
00277 /** @defgroup UTILS_EF_SYSTEM SYSTEM
00278   * @{
00279   */
00280 
00281 void        LL_SetSystemCoreClock(uint32_t HCLKFrequency);
00282 ErrorStatus LL_SetFlashLatency(uint32_t HCLK_Frequency);
00283 ErrorStatus LL_PLL_ConfigSystemClock_HSI(LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct,
00284                                          LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct);
00285 ErrorStatus LL_PLL_ConfigSystemClock_HSE(uint32_t HSEFrequency, uint32_t HSEBypass,
00286                                          LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct);
00287 
00288 /**
00289   * @}
00290   */
00291 
00292 /**
00293   * @}
00294   */
00295 
00296 /**
00297   * @}
00298   */
00299 
00300 /**
00301   * @}
00302   */
00303 
00304 #ifdef __cplusplus
00305 }
00306 #endif
00307 
00308 #endif /* __STM32F4xx_LL_UTILS_H */
00309 
00310 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/