STM32L486xx HAL User Manual
stm32l4xx_ll_utils.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_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</center></h2>
00022   *
00023   * Redistribution and use in source and binary forms, with or without modification,
00024   * are permitted provided that the following conditions are met:
00025   *   1. Redistributions of source code must retain the above copyright notice,
00026   *      this list of conditions and the following disclaimer.
00027   *   2. Redistributions in binary form must reproduce the above copyright notice,
00028   *      this list of conditions and the following disclaimer in the documentation
00029   *      and/or other materials provided with the distribution.
00030   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00031   *      may be used to endorse or promote products derived from this software
00032   *      without specific prior written permission.
00033   *
00034   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00035   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00036   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00037   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00038   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00039   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00040   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00041   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00042   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00043   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00044   *
00045   ******************************************************************************
00046   */
00047 
00048 /* Define to prevent recursive inclusion -------------------------------------*/
00049 #ifndef __STM32L4xx_LL_UTILS_H
00050 #define __STM32L4xx_LL_UTILS_H
00051 
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055 
00056 /* Includes ------------------------------------------------------------------*/
00057 #include "stm32l4xx.h"
00058 
00059 /** @addtogroup STM32L4xx_LL_Driver
00060   * @{
00061   */
00062 
00063 /** @defgroup UTILS_LL UTILS
00064   * @{
00065   */
00066 
00067 /* Private types -------------------------------------------------------------*/
00068 /* Private variables ---------------------------------------------------------*/
00069 
00070 /* Private constants ---------------------------------------------------------*/
00071 /** @defgroup UTILS_LL_Private_Constants UTILS Private Constants
00072   * @{
00073   */
00074 
00075 /* Max delay can be used in LL_mDelay */
00076 #define LL_MAX_DELAY                  0xFFFFFFFFU
00077 
00078 /**
00079  * @brief Unique device ID register base address
00080  */
00081 #define UID_BASE_ADDRESS              UID_BASE
00082 
00083 /**
00084  * @brief Flash size data register base address
00085  */
00086 #define FLASHSIZE_BASE_ADDRESS        FLASHSIZE_BASE
00087 
00088 /**
00089  * @brief Package data register base address
00090  */
00091 #define PACKAGE_BASE_ADDRESS          PACKAGE_BASE
00092 
00093 /**
00094   * @}
00095   */
00096 
00097 /* Private macros ------------------------------------------------------------*/
00098 /** @defgroup UTILS_LL_Private_Macros UTILS Private Macros
00099   * @{
00100   */
00101 /**
00102   * @}
00103   */
00104 /* Exported types ------------------------------------------------------------*/
00105 /** @defgroup UTILS_LL_ES_INIT UTILS Exported structures
00106   * @{
00107   */
00108 /**
00109   * @brief  UTILS PLL structure definition
00110   */
00111 typedef struct
00112 {
00113   uint32_t PLLM;   /*!< Division factor for PLL VCO input clock.
00114                         This parameter can be a value of @ref RCC_LL_EC_PLLM_DIV
00115 
00116                         This feature can be modified afterwards using unitary function
00117                         @ref LL_RCC_PLL_ConfigDomain_SYS(). */
00118 
00119   uint32_t PLLN;   /*!< Multiplication factor for PLL VCO output clock.
00120                         This parameter must be a number between Min_Data = 8 and Max_Data = 86
00121 
00122                         This feature can be modified afterwards using unitary function
00123                         @ref LL_RCC_PLL_ConfigDomain_SYS(). */
00124 
00125   uint32_t PLLR;   /*!< Division for the main system clock.
00126                         This parameter can be a value of @ref RCC_LL_EC_PLLR_DIV
00127 
00128                         This feature can be modified afterwards using unitary function
00129                         @ref LL_RCC_PLL_ConfigDomain_SYS(). */
00130 } LL_UTILS_PLLInitTypeDef;
00131 
00132 /**
00133   * @brief  UTILS System, AHB and APB buses clock configuration structure definition
00134   */
00135 typedef struct
00136 {
00137   uint32_t AHBCLKDivider;         /*!< The AHB clock (HCLK) divider. This clock is derived from the system clock (SYSCLK).
00138                                        This parameter can be a value of @ref RCC_LL_EC_SYSCLK_DIV
00139 
00140                                        This feature can be modified afterwards using unitary function
00141                                        @ref LL_RCC_SetAHBPrescaler(). */
00142 
00143   uint32_t APB1CLKDivider;        /*!< The APB1 clock (PCLK1) divider. This clock is derived from the AHB clock (HCLK).
00144                                        This parameter can be a value of @ref RCC_LL_EC_APB1_DIV
00145 
00146                                        This feature can be modified afterwards using unitary function
00147                                        @ref LL_RCC_SetAPB1Prescaler(). */
00148 
00149   uint32_t APB2CLKDivider;        /*!< The APB2 clock (PCLK2) divider. This clock is derived from the AHB clock (HCLK).
00150                                        This parameter can be a value of @ref RCC_LL_EC_APB2_DIV
00151 
00152                                        This feature can be modified afterwards using unitary function
00153                                        @ref LL_RCC_SetAPB2Prescaler(). */
00154 
00155 } LL_UTILS_ClkInitTypeDef;
00156 
00157 /**
00158   * @}
00159   */
00160 
00161 /* Exported constants --------------------------------------------------------*/
00162 /** @defgroup UTILS_LL_Exported_Constants UTILS Exported Constants
00163   * @{
00164   */
00165 
00166 /** @defgroup UTILS_EC_HSE_BYPASS HSE Bypass activation
00167   * @{
00168   */
00169 #define LL_UTILS_HSEBYPASS_OFF        0x00000000U       /*!< HSE Bypass is not enabled                */
00170 #define LL_UTILS_HSEBYPASS_ON         0x00000001U       /*!< HSE Bypass is enabled                    */
00171 /**
00172   * @}
00173   */
00174 
00175 /** @defgroup UTILS_EC_PACKAGETYPE PACKAGE TYPE
00176   * @{
00177   */
00178 #define LL_UTILS_PACKAGETYPE_LQFP64         0x00000000U /*!< LQFP64 package type                      */
00179 #define LL_UTILS_PACKAGETYPE_WLCSP64        0x00000001U /*!< WLCSP64 package type                     */
00180 #define LL_UTILS_PACKAGETYPE_LQFP100        0x00000002U /*!< LQFP100 package type                     */
00181 #define LL_UTILS_PACKAGETYPE_BGA132         0x00000003U /*!< BGA132 package type                      */
00182 #define LL_UTILS_PACKAGETYPE_LQFP144_CSP72  0x00000004U /*!< LQFP144, WLCSP81 or WLCSP72 package type */
00183 #define LL_UTILS_PACKAGETYPE_UFQFPN32       0x00000008U /*!< UFQFPN32 package type                    */
00184 #define LL_UTILS_PACKAGETYPE_UFQFPN48       0x0000000AU /*!< UFQFPN48 package type                    */
00185 #define LL_UTILS_PACKAGETYPE_LQFP48         0x0000000BU /*!< LQFP48 package type                      */
00186 #define LL_UTILS_PACKAGETYPE_WLCSP49        0x0000000CU /*!< WLCSP49 package type                     */
00187 #define LL_UTILS_PACKAGETYPE_UFBGA64        0x0000000DU /*!< UFBGA64 package type                     */
00188 #define LL_UTILS_PACKAGETYPE_UFBGA100       0x0000000EU /*!< UFBGA100 package type                    */
00189 #define LL_UTILS_PACKAGETYPE_UFBGA169       0x00000010U /*!< UFBGA169 package type                    */
00190 #define LL_UTILS_PACKAGETYPE_LQFP100_DSI    0x00000012U /*!< LQFP100 with DSI package type            */
00191 #define LL_UTILS_PACKAGETYPE_WLCSP144_DSI   0x00000013U /*!< WLCSP144 with DSI package type           */
00192 #define LL_UTILS_PACKAGETYPE_UFBGA144_DSI   0x00000013U /*!< UFBGA144 with DSI package type           */
00193 #define LL_UTILS_PACKAGETYPE_UFBGA169_DSI   0x00000014U /*!< UFBGA169 with DSI package type           */
00194 #define LL_UTILS_PACKAGETYPE_LQFP144_DSI    0x00000015U /*!< LQFP144 with DSI package type            */
00195 /**
00196   * @}
00197   */
00198 
00199 /**
00200   * @}
00201   */
00202 
00203 /* Exported macro ------------------------------------------------------------*/
00204 
00205 /* Exported functions --------------------------------------------------------*/
00206 /** @defgroup UTILS_LL_Exported_Functions UTILS Exported Functions
00207   * @{
00208   */
00209 
00210 /** @defgroup UTILS_EF_DEVICE_ELECTRONIC_SIGNATURE DEVICE ELECTRONIC SIGNATURE
00211   * @{
00212   */
00213 
00214 /**
00215   * @brief  Get Word0 of the unique device identifier (UID based on 96 bits)
00216   * @retval UID[31:0]: X and Y coordinates on the wafer expressed in BCD format
00217   */
00218 __STATIC_INLINE uint32_t LL_GetUID_Word0(void)
00219 {
00220   return (uint32_t)(READ_REG(*((uint32_t *)UID_BASE_ADDRESS)));
00221 }
00222 
00223 /**
00224   * @brief  Get Word1 of the unique device identifier (UID based on 96 bits)
00225   * @retval UID[63:32]: Wafer number (UID[39:32]) & LOT_NUM[23:0] (UID[63:40])
00226   */
00227 __STATIC_INLINE uint32_t LL_GetUID_Word1(void)
00228 {
00229   return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 4U))));
00230 }
00231 
00232 /**
00233   * @brief  Get Word2 of the unique device identifier (UID based on 96 bits)
00234   * @retval UID[95:64]: Lot number (ASCII encoded) - LOT_NUM[55:24]
00235   */
00236 __STATIC_INLINE uint32_t LL_GetUID_Word2(void)
00237 {
00238   return (uint32_t)(READ_REG(*((uint32_t *)(UID_BASE_ADDRESS + 8U))));
00239 }
00240 
00241 /**
00242   * @brief  Get Flash memory size
00243   * @note   This bitfield indicates the size of the device Flash memory expressed in
00244   *         Kbytes. As an example, 0x040 corresponds to 64 Kbytes.
00245   * @retval FLASH_SIZE[15:0]: Flash memory size
00246   */
00247 __STATIC_INLINE uint32_t LL_GetFlashSize(void)
00248 {
00249   return (uint32_t)(READ_REG(*((uint32_t *)FLASHSIZE_BASE_ADDRESS)) & 0xFFFFU);
00250 }
00251 
00252 /**
00253   * @brief  Get Package type
00254   * @retval Returned value can be one of the following values:
00255   *         @arg @ref LL_UTILS_PACKAGETYPE_LQFP64 (*)
00256   *         @arg @ref LL_UTILS_PACKAGETYPE_LQFP100 (*)
00257   *         @arg @ref LL_UTILS_PACKAGETYPE_BGA132 (*)
00258   *         @arg @ref LL_UTILS_PACKAGETYPE_LQFP144_CSP72 (*)
00259   *         @arg @ref LL_UTILS_PACKAGETYPE_UFQFPN32 (*)
00260   *         @arg @ref LL_UTILS_PACKAGETYPE_UFQFPN48 (*)
00261   *         @arg @ref LL_UTILS_PACKAGETYPE_LQFP48 (*)
00262   *         @arg @ref LL_UTILS_PACKAGETYPE_WLCSP49 (*)
00263   *         @arg @ref LL_UTILS_PACKAGETYPE_UFBGA64 (*)
00264   *         @arg @ref LL_UTILS_PACKAGETYPE_UFBGA100 (*)
00265   *         @arg @ref LL_UTILS_PACKAGETYPE_UFBGA169 (*)
00266   *         @arg @ref LL_UTILS_PACKAGETYPE_LQFP100_DSI (*)
00267   *         @arg @ref LL_UTILS_PACKAGETYPE_WLCSP144_DSI (*)
00268   *         @arg @ref LL_UTILS_PACKAGETYPE_UFBGA144_DSI (*)
00269   *         @arg @ref LL_UTILS_PACKAGETYPE_UFBGA169_DSI (*)
00270   *         @arg @ref LL_UTILS_PACKAGETYPE_LQFP144_DSI (*)
00271   *
00272   *         (*) value not defined in all devices.
00273   */
00274 __STATIC_INLINE uint32_t LL_GetPackageType(void)
00275 {
00276   return (uint32_t)(READ_REG(*((uint32_t *)PACKAGE_BASE_ADDRESS)) & 0x1FU);
00277 }
00278 
00279 /**
00280   * @}
00281   */
00282 
00283 /** @defgroup UTILS_LL_EF_DELAY DELAY
00284   * @{
00285   */
00286 
00287 /**
00288   * @brief  This function configures the Cortex-M SysTick source of the time base.
00289   * @param  HCLKFrequency HCLK frequency in Hz (can be calculated thanks to RCC helper macro)
00290   * @note   When a RTOS is used, it is recommended to avoid changing the SysTick
00291   *         configuration by calling this function, for a delay use rather osDelay RTOS service.
00292   * @param  Ticks Number of ticks
00293   * @retval None
00294   */
00295 __STATIC_INLINE void LL_InitTick(uint32_t HCLKFrequency, uint32_t Ticks)
00296 {
00297   /* Configure the SysTick to have interrupt in 1ms time base */
00298   SysTick->LOAD  = (uint32_t)((HCLKFrequency / Ticks) - 1UL);  /* set reload register */
00299   SysTick->VAL   = 0UL;                                       /* Load the SysTick Counter Value */
00300   SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
00301                    SysTick_CTRL_ENABLE_Msk;                   /* Enable the Systick Timer */
00302 }
00303 
00304 void        LL_Init1msTick(uint32_t HCLKFrequency);
00305 void        LL_mDelay(uint32_t Delay);
00306 
00307 /**
00308   * @}
00309   */
00310 
00311 /** @defgroup UTILS_EF_SYSTEM SYSTEM
00312   * @{
00313   */
00314 
00315 void        LL_SetSystemCoreClock(uint32_t HCLKFrequency);
00316 ErrorStatus LL_PLL_ConfigSystemClock_MSI(LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct,
00317                                          LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct);
00318 ErrorStatus LL_PLL_ConfigSystemClock_HSI(LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct,
00319                                          LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct);
00320 ErrorStatus LL_PLL_ConfigSystemClock_HSE(uint32_t HSEFrequency, uint32_t HSEBypass,
00321                                          LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct);
00322 
00323 /**
00324   * @}
00325   */
00326 
00327 /**
00328   * @}
00329   */
00330 
00331 /**
00332   * @}
00333   */
00334 
00335 /**
00336   * @}
00337   */
00338 
00339 #ifdef __cplusplus
00340 }
00341 #endif
00342 
00343 #endif /* __STM32L4xx_LL_UTILS_H */
00344 
00345 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/