STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_ll_utils.c 00004 * @author MCD Application Team 00005 * @brief UTILS LL module driver. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file in 00013 * the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 /* Includes ------------------------------------------------------------------*/ 00019 #include "stm32h7xx_ll_utils.h" 00020 #include "stm32h7xx_ll_rcc.h" 00021 #include "stm32h7xx_ll_pwr.h" 00022 00023 #ifdef USE_FULL_ASSERT 00024 #include "stm32_assert.h" 00025 #else 00026 #define assert_param(expr) ((void)0U) 00027 #endif /* USE_FULL_ASSERT */ 00028 00029 /** @addtogroup STM32H7xx_LL_Driver 00030 * @{ 00031 */ 00032 00033 /** @addtogroup UTILS_LL 00034 * @{ 00035 */ 00036 00037 /* Private types -------------------------------------------------------------*/ 00038 /* Private variables ---------------------------------------------------------*/ 00039 /* Private constants ---------------------------------------------------------*/ 00040 /** @addtogroup UTILS_LL_Private_Constants 00041 * @{ 00042 */ 00043 #if (STM32H7_DEV_ID == 0x450UL) 00044 #define UTILS_MAX_FREQUENCY_SCALE1 480000000U /*!< Maximum frequency for system clock at power scale1, in Hz */ 00045 #define UTILS_MAX_FREQUENCY_SCALE2 300000000U /*!< Maximum frequency for system clock at power scale2, in Hz */ 00046 #define UTILS_MAX_FREQUENCY_SCALE3 200000000U /*!< Maximum frequency for system clock at power scale3, in Hz */ 00047 #elif (STM32H7_DEV_ID == 0x480UL) 00048 #define UTILS_MAX_FREQUENCY_SCALE0 280000000U /*!< Maximum frequency for system clock at power scale0, in Hz */ 00049 #define UTILS_MAX_FREQUENCY_SCALE1 225000000U /*!< Maximum frequency for system clock at power scale1, in Hz */ 00050 #define UTILS_MAX_FREQUENCY_SCALE2 160000000U /*!< Maximum frequency for system clock at power scale2, in Hz */ 00051 #define UTILS_MAX_FREQUENCY_SCALE3 88000000U /*!< Maximum frequency for system clock at power scale3, in Hz */ 00052 #elif (STM32H7_DEV_ID == 0x483UL) 00053 #define UTILS_MAX_FREQUENCY_SCALE0 550000000U /*!< Maximum frequency for system clock at power scale0, in Hz */ 00054 #define UTILS_MAX_FREQUENCY_SCALE1 200000000U /*!< Maximum frequency for system clock at power scale1, in Hz */ 00055 #define UTILS_MAX_FREQUENCY_SCALE2 150000000U /*!< Maximum frequency for system clock at power scale2, in Hz */ 00056 #define UTILS_MAX_FREQUENCY_SCALE3 85000000U /*!< Maximum frequency for system clock at power scale3, in Hz */ 00057 #endif /*STM32H7_DEV_ID == 0x450UL*/ 00058 00059 /* Defines used for PLL range */ 00060 #define UTILS_PLLVCO_INPUT_MIN1 1000000U /*!< Frequency min for the low range PLLVCO input, in Hz */ 00061 #define UTILS_PLLVCO_INPUT_MAX1 2000000U /*!< Frequency max for the wide range PLLVCO input, in Hz */ 00062 #define UTILS_PLLVCO_INPUT_MIN2 2000000U /*!< Frequency min for the low range PLLVCO input, in Hz */ 00063 #define UTILS_PLLVCO_INPUT_MAX2 4000000U /*!< Frequency max for the wide range PLLVCO input, in Hz */ 00064 #define UTILS_PLLVCO_INPUT_MIN3 4000000U /*!< Frequency min for the low range PLLVCO input, in Hz */ 00065 #define UTILS_PLLVCO_INPUT_MAX3 8000000U /*!< Frequency max for the wide range PLLVCO input, in Hz */ 00066 #define UTILS_PLLVCO_INPUT_MIN4 8000000U /*!< Frequency min for the low range PLLVCO input, in Hz */ 00067 #define UTILS_PLLVCO_INPUT_MAX4 16000000U /*!< Frequency max for the wide range PLLVCO input, in Hz */ 00068 00069 #if (POWER_DOMAINS_NUMBER == 3U) 00070 #define UTILS_PLLVCO_MEDIUM_OUTPUT_MIN 150000000U /*!< Frequency min for the medium range PLLVCO output, in Hz */ 00071 #define UTILS_PLLVCO_WIDE_OUTPUT_MIN 192000000U /*!< Frequency min for the wide range PLLVCO output, in Hz */ 00072 #define UTILS_PLLVCO_MEDIUM_OUTPUT_MAX 420000000U /*!< Frequency max for the medium range PLLVCO output, in Hz */ 00073 #define UTILS_PLLVCO_WIDE_OUTPUT_MAX 836000000U /*!< Frequency max for the wide range PLLVCO output, in Hz */ 00074 #else 00075 #define UTILS_PLLVCO_MEDIUM_OUTPUT_MIN 150000000U /*!< Frequency min for the medium range PLLVCO output, in Hz */ 00076 #define UTILS_PLLVCO_WIDE_OUTPUT_MIN 128000000U /*!< Frequency min for the wide range PLLVCO output, in Hz */ 00077 #define UTILS_PLLVCO_MEDIUM_OUTPUT_MAX 420000000U /*!< Frequency max for the medium range PLLVCO output, in Hz */ 00078 #define UTILS_PLLVCO_WIDE_OUTPUT_MAX 560000000U /*!< Frequency max for the wide range PLLVCO output, in Hz */ 00079 #endif /*POWER_DOMAINS_NUMBER == 3U*/ 00080 00081 /* Defines used for HSE range */ 00082 #define UTILS_HSE_FREQUENCY_MIN 4000000U /*!< Frequency min for HSE frequency, in Hz */ 00083 #define UTILS_HSE_FREQUENCY_MAX 48000000U /*!< Frequency max for HSE frequency, in Hz */ 00084 00085 /* Defines used for FLASH latency according to HCLK Frequency */ 00086 #if (STM32H7_DEV_ID == 0x480UL) 00087 #define UTILS_SCALE0_LATENCY0_FREQ 44000000U /*!< HCLK frequency to set FLASH latency 0 in power scale 0 */ 00088 #define UTILS_SCALE0_LATENCY1_FREQ 88000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 0 */ 00089 #define UTILS_SCALE0_LATENCY2_FREQ 132000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 0 */ 00090 #define UTILS_SCALE0_LATENCY3_FREQ 176000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 0 */ 00091 #define UTILS_SCALE0_LATENCY4_FREQ 220000000U /*!< HCLK frequency to set FLASH latency 4 in power scale 0 */ 00092 #define UTILS_SCALE0_LATENCY5_FREQ 264000000U /*!< HCLK frequency to set FLASH latency 5 in power scale 0 */ 00093 #define UTILS_SCALE0_LATENCY6_FREQ 280000000U /*!< HCLK frequency to set FLASH latency 6 in power scale 0 */ 00094 00095 #define UTILS_SCALE1_LATENCY0_FREQ 42000000U /*!< HCLK frequency to set FLASH latency 0 in power scale 1 */ 00096 #define UTILS_SCALE1_LATENCY1_FREQ 84000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 1 */ 00097 #define UTILS_SCALE1_LATENCY2_FREQ 126000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 1 */ 00098 #define UTILS_SCALE1_LATENCY3_FREQ 168000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 1 */ 00099 #define UTILS_SCALE1_LATENCY4_FREQ 210000000U /*!< HCLK frequency to set FLASH latency 4 in power scale 1 */ 00100 #define UTILS_SCALE1_LATENCY5_FREQ 225000000U /*!< HCLK frequency to set FLASH latency 5 in power scale 1 */ 00101 00102 #define UTILS_SCALE2_LATENCY0_FREQ 34000000U /*!< HCLK frequency to set FLASH latency 0 in power scale 2 */ 00103 #define UTILS_SCALE2_LATENCY1_FREQ 68000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 2 */ 00104 #define UTILS_SCALE2_LATENCY2_FREQ 102000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 2 */ 00105 #define UTILS_SCALE2_LATENCY3_FREQ 136000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 2 */ 00106 #define UTILS_SCALE2_LATENCY4_FREQ 160000000U /*!< HCLK frequency to set FLASH latency 4 in power scale 2 */ 00107 00108 #define UTILS_SCALE3_LATENCY0_FREQ 22000000U /*!< HCLK frequency to set FLASH latency 0 in power scale 3 */ 00109 #define UTILS_SCALE3_LATENCY1_FREQ 44000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 3 */ 00110 #define UTILS_SCALE3_LATENCY2_FREQ 66000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 3 */ 00111 #define UTILS_SCALE3_LATENCY3_FREQ 88000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 3 */ 00112 00113 #elif (STM32H7_DEV_ID == 0x450UL) 00114 00115 #define UTILS_SCALE1_LATENCY0_FREQ 70000000U /*!< HCLK frequency to set FLASH latency 0 in power scale 1 */ 00116 #define UTILS_SCALE1_LATENCY1_FREQ 140000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 1 */ 00117 #define UTILS_SCALE1_LATENCY2_FREQ 240000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 1 */ 00118 00119 #define UTILS_SCALE2_LATENCY0_FREQ 55000000U /*!< HCLK frequency to set FLASH latency 0 in power scale 2 */ 00120 #define UTILS_SCALE2_LATENCY1_FREQ 110000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 2 */ 00121 #define UTILS_SCALE2_LATENCY2_FREQ 165000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 2 */ 00122 #define UTILS_SCALE2_LATENCY3_FREQ 220000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 2 */ 00123 00124 #define UTILS_SCALE3_LATENCY0_FREQ 45000000U /*!< HCLK frequency to set FLASH latency 0 in power scale 3 */ 00125 #define UTILS_SCALE3_LATENCY1_FREQ 90000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 3 */ 00126 #define UTILS_SCALE3_LATENCY2_FREQ 135000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 3 */ 00127 #define UTILS_SCALE3_LATENCY3_FREQ 180000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 3 */ 00128 #define UTILS_SCALE3_LATENCY4_FREQ 225000000U /*!< HCLK frequency to set FLASH latency 4 in power scale 3 */ 00129 00130 #elif (STM32H7_DEV_ID == 0x483UL) 00131 00132 #define UTILS_SCALE0_LATENCY0_FREQ 70000000U /*!< HCLK frequency to set FLASH latency 0 in power scale 0 */ 00133 #define UTILS_SCALE0_LATENCY1_FREQ 140000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 0 */ 00134 #define UTILS_SCALE0_LATENCY2_FREQ 210000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 0 */ 00135 #define UTILS_SCALE0_LATENCY3_FREQ 275000000U /*!< HCLK frequency to set FLASH latency 3 in power scale 0 */ 00136 00137 #define UTILS_SCALE1_LATENCY0_FREQ 67000000U /*!< HCLK frequency to set FLASH latency 0 in power scale 1 */ 00138 #define UTILS_SCALE1_LATENCY1_FREQ 133000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 1 */ 00139 #define UTILS_SCALE1_LATENCY2_FREQ 200000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 1 */ 00140 00141 #define UTILS_SCALE2_LATENCY0_FREQ 50000000U /*!< HCLK frequency to set FLASH latency 0 in power scale 2 */ 00142 #define UTILS_SCALE2_LATENCY1_FREQ 100000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 2 */ 00143 #define UTILS_SCALE2_LATENCY2_FREQ 150000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 2 */ 00144 00145 #define UTILS_SCALE3_LATENCY0_FREQ 35000000U /*!< HCLK frequency to set FLASH latency 0 in power scale 3 */ 00146 #define UTILS_SCALE3_LATENCY1_FREQ 70000000U /*!< HCLK frequency to set FLASH latency 1 in power scale 3 */ 00147 #define UTILS_SCALE3_LATENCY2_FREQ 85000000U /*!< HCLK frequency to set FLASH latency 2 in power scale 3 */ 00148 00149 #endif /*STM32H7_DEV_ID == 0x480UL*/ 00150 /** 00151 * @} 00152 */ 00153 00154 /* Private macros ------------------------------------------------------------*/ 00155 /** @addtogroup UTILS_LL_Private_Macros 00156 * @{ 00157 */ 00158 #define IS_LL_UTILS_SYSCLK_DIV(__VALUE__) (((__VALUE__) == LL_RCC_SYSCLK_DIV_1) \ 00159 || ((__VALUE__) == LL_RCC_SYSCLK_DIV_2) \ 00160 || ((__VALUE__) == LL_RCC_SYSCLK_DIV_4) \ 00161 || ((__VALUE__) == LL_RCC_SYSCLK_DIV_8) \ 00162 || ((__VALUE__) == LL_RCC_SYSCLK_DIV_16) \ 00163 || ((__VALUE__) == LL_RCC_SYSCLK_DIV_64) \ 00164 || ((__VALUE__) == LL_RCC_SYSCLK_DIV_128) \ 00165 || ((__VALUE__) == LL_RCC_SYSCLK_DIV_256) \ 00166 || ((__VALUE__) == LL_RCC_SYSCLK_DIV_512)) 00167 00168 #define IS_LL_UTILS_AHB_DIV(__VALUE__) (((__VALUE__) == LL_RCC_AHB_DIV_1) \ 00169 || ((__VALUE__) == LL_RCC_AHB_DIV_2) \ 00170 || ((__VALUE__) == LL_RCC_AHB_DIV_4) \ 00171 || ((__VALUE__) == LL_RCC_AHB_DIV_8) \ 00172 || ((__VALUE__) == LL_RCC_AHB_DIV_16) \ 00173 || ((__VALUE__) == LL_RCC_AHB_DIV_64) \ 00174 || ((__VALUE__) == LL_RCC_AHB_DIV_128) \ 00175 || ((__VALUE__) == LL_RCC_AHB_DIV_256) \ 00176 || ((__VALUE__) == LL_RCC_AHB_DIV_512)) 00177 00178 #define IS_LL_UTILS_APB1_DIV(__VALUE__) (((__VALUE__) == LL_RCC_APB1_DIV_1) \ 00179 || ((__VALUE__) == LL_RCC_APB1_DIV_2) \ 00180 || ((__VALUE__) == LL_RCC_APB1_DIV_4) \ 00181 || ((__VALUE__) == LL_RCC_APB1_DIV_8) \ 00182 || ((__VALUE__) == LL_RCC_APB1_DIV_16)) 00183 00184 #define IS_LL_UTILS_APB2_DIV(__VALUE__) (((__VALUE__) == LL_RCC_APB2_DIV_1) \ 00185 || ((__VALUE__) == LL_RCC_APB2_DIV_2) \ 00186 || ((__VALUE__) == LL_RCC_APB2_DIV_4) \ 00187 || ((__VALUE__) == LL_RCC_APB2_DIV_8) \ 00188 || ((__VALUE__) == LL_RCC_APB2_DIV_16)) 00189 00190 #define IS_LL_UTILS_APB3_DIV(__VALUE__) (((__VALUE__) == LL_RCC_APB3_DIV_1) \ 00191 || ((__VALUE__) == LL_RCC_APB3_DIV_2) \ 00192 || ((__VALUE__) == LL_RCC_APB3_DIV_4) \ 00193 || ((__VALUE__) == LL_RCC_APB3_DIV_8) \ 00194 || ((__VALUE__) == LL_RCC_APB3_DIV_16)) 00195 00196 #define IS_LL_UTILS_APB4_DIV(__VALUE__) (((__VALUE__) == LL_RCC_APB4_DIV_1) \ 00197 || ((__VALUE__) == LL_RCC_APB4_DIV_2) \ 00198 || ((__VALUE__) == LL_RCC_APB4_DIV_4) \ 00199 || ((__VALUE__) == LL_RCC_APB4_DIV_8) \ 00200 || ((__VALUE__) == LL_RCC_APB4_DIV_16)) 00201 00202 #define IS_LL_UTILS_PLLM_VALUE(__VALUE__) ((1U <= (__VALUE__)) && ((__VALUE__) <= 63U)) 00203 00204 #if (POWER_DOMAINS_NUMBER == 3U) 00205 #define IS_LL_UTILS_PLLN_VALUE(__VALUE__) ((4U <= (__VALUE__)) && ((__VALUE__) <= 512U)) 00206 #else 00207 #define IS_LL_UTILS_PLLN_VALUE(__VALUE__) ((8U <= (__VALUE__)) && ((__VALUE__) <= 420U)) 00208 #endif /*POWER_DOMAINS_NUMBER == 3U*/ 00209 00210 #define IS_LL_UTILS_PLLP_VALUE(__VALUE__) ((1U <= (__VALUE__)) && ((__VALUE__) <= 128U)) 00211 00212 #define IS_LL_UTILS_FRACN_VALUE(__VALUE__) ((__VALUE__) <= 0x1FFFU) 00213 00214 #define IS_LL_UTILS_PLLVCO_INPUT(__VALUE__, __RANGE__) ( \ 00215 (((__RANGE__) == LL_RCC_PLLINPUTRANGE_1_2) && (UTILS_PLLVCO_INPUT_MIN1 <= (__VALUE__)) && ((__VALUE__) <= UTILS_PLLVCO_INPUT_MAX1)) || \ 00216 (((__RANGE__) == LL_RCC_PLLINPUTRANGE_2_4) && (UTILS_PLLVCO_INPUT_MIN2 <= (__VALUE__)) && ((__VALUE__) <= UTILS_PLLVCO_INPUT_MAX2)) || \ 00217 (((__RANGE__) == LL_RCC_PLLINPUTRANGE_4_8) && (UTILS_PLLVCO_INPUT_MIN3 <= (__VALUE__)) && ((__VALUE__) <= UTILS_PLLVCO_INPUT_MAX3)) || \ 00218 (((__RANGE__) == LL_RCC_PLLINPUTRANGE_8_16) && (UTILS_PLLVCO_INPUT_MIN4 <= (__VALUE__)) && ((__VALUE__) <= UTILS_PLLVCO_INPUT_MAX4))) 00219 00220 #define IS_LL_UTILS_PLLVCO_OUTPUT(__VALUE__, __RANGE__) ( \ 00221 (((__RANGE__) == LL_RCC_PLLVCORANGE_MEDIUM) && (UTILS_PLLVCO_MEDIUM_OUTPUT_MIN <= (__VALUE__)) && ((__VALUE__) <= UTILS_PLLVCO_MEDIUM_OUTPUT_MAX)) || \ 00222 (((__RANGE__) == LL_RCC_PLLVCORANGE_WIDE) && (UTILS_PLLVCO_WIDE_OUTPUT_MIN <= (__VALUE__)) && ((__VALUE__) <= UTILS_PLLVCO_WIDE_OUTPUT_MAX))) 00223 00224 #define IS_LL_UTILS_CHECK_VCO_RANGES(__RANGEIN__, __RANGEOUT__) ( \ 00225 (((__RANGEIN__) == LL_RCC_PLLINPUTRANGE_1_2) && ((__RANGEOUT__) == LL_RCC_PLLVCORANGE_MEDIUM)) || \ 00226 (((__RANGEIN__) != LL_RCC_PLLINPUTRANGE_1_2) && ((__RANGEOUT__) == LL_RCC_PLLVCORANGE_WIDE))) 00227 00228 #if (STM32H7_DEV_ID == 0x450UL) 00229 #define IS_LL_UTILS_PLL_FREQUENCY(__VALUE__) ((LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE1) ? ((__VALUE__) <= UTILS_MAX_FREQUENCY_SCALE1) : \ 00230 (LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE2) ? ((__VALUE__) <= UTILS_MAX_FREQUENCY_SCALE2) : \ 00231 ((__VALUE__) <= UTILS_MAX_FREQUENCY_SCALE3)) 00232 #else 00233 #define IS_LL_UTILS_PLL_FREQUENCY(__VALUE__) ((LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE0) ? ((__VALUE__) <= UTILS_MAX_FREQUENCY_SCALE0) : \ 00234 (LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE1) ? ((__VALUE__) <= UTILS_MAX_FREQUENCY_SCALE1) : \ 00235 (LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE2) ? ((__VALUE__) <= UTILS_MAX_FREQUENCY_SCALE2) : \ 00236 ((__VALUE__) <= UTILS_MAX_FREQUENCY_SCALE3)) 00237 #endif /* STM32H7_DEV_ID == 0x450UL */ 00238 00239 #define IS_LL_UTILS_HSE_BYPASS(__STATE__) (((__STATE__) == LL_UTILS_HSEBYPASS_ON) \ 00240 || ((__STATE__) == LL_UTILS_HSEBYPASS_OFF)) 00241 00242 #define IS_LL_UTILS_HSE_FREQUENCY(__FREQUENCY__) (((__FREQUENCY__) >= UTILS_HSE_FREQUENCY_MIN) && ((__FREQUENCY__) <= UTILS_HSE_FREQUENCY_MAX)) 00243 /** 00244 * @} 00245 */ 00246 /* Private function prototypes -----------------------------------------------*/ 00247 /** @defgroup UTILS_LL_Private_Functions UTILS Private functions 00248 * @{ 00249 */ 00250 static uint32_t UTILS_GetPLLOutputFrequency(uint32_t PLL_InputFrequency, LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct); 00251 static ErrorStatus UTILS_EnablePLLAndSwitchSystem(uint32_t SYSCLK_Frequency, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct); 00252 static ErrorStatus UTILS_IsPLLsReady(void); 00253 /** 00254 * @} 00255 */ 00256 00257 /* Exported functions --------------------------------------------------------*/ 00258 /** @addtogroup UTILS_LL_Exported_Functions 00259 * @{ 00260 */ 00261 00262 /** @addtogroup UTILS_LL_EF_DELAY 00263 * @{ 00264 */ 00265 #if defined (DUAL_CORE) 00266 /** 00267 * @brief This function configures the Cortex-M SysTick source to have 1ms time base. 00268 * @note When a RTOS is used, it is recommended to avoid changing the Systick 00269 * configuration by calling this function, for a delay use rather osDelay RTOS service. 00270 * @param CPU_Frequency Core frequency in Hz 00271 * @note CPU_Frequency can be calculated thanks to RCC helper macro or function 00272 * @ref LL_RCC_GetSystemClocksFreq 00273 * LL_RCC_GetSystemClocksFreq() is used to calculate the CM7 clock frequency 00274 * and __LL_RCC_CALC_HCLK_FREQ is used to calculate the CM4 clock frequency. 00275 * @retval None 00276 */ 00277 #else 00278 /** 00279 * @brief This function configures the Cortex-M SysTick source to have 1ms time base. 00280 * @note When a RTOS is used, it is recommended to avoid changing the Systick 00281 * configuration by calling this function, for a delay use rather osDelay RTOS service. 00282 * @param CPU_Frequency Core frequency in Hz 00283 * @note CPU_Frequency can be calculated thanks to RCC helper macro or function 00284 * @ref LL_RCC_GetSystemClocksFreq 00285 * @retval None 00286 */ 00287 #endif /* DUAL_CORE */ 00288 void LL_Init1msTick(uint32_t CPU_Frequency) 00289 { 00290 /* Use frequency provided in argument */ 00291 LL_InitTick(CPU_Frequency, 1000U); 00292 } 00293 00294 00295 /** 00296 * @brief This function provides accurate delay (in milliseconds) based 00297 * on SysTick counter flag 00298 * @note When a RTOS is used, it is recommended to avoid using blocking delay 00299 * and use rather osDelay service. 00300 * @note To respect 1ms timebase, user should call @ref LL_Init1msTick function which 00301 * will configure Systick to 1ms 00302 * @param Delay specifies the delay time length, in milliseconds. 00303 * @retval None 00304 */ 00305 void LL_mDelay(uint32_t Delay) 00306 { 00307 uint32_t count = Delay; 00308 __IO uint32_t tmp = SysTick->CTRL; /* Clear the COUNTFLAG first */ 00309 /* Add this code to indicate that local variable is not used */ 00310 ((void)tmp); 00311 00312 /* Add a period to guaranty minimum wait */ 00313 if(count < LL_MAX_DELAY) 00314 { 00315 count++; 00316 } 00317 00318 while (count != 0U) 00319 { 00320 if((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) != 0U) 00321 { 00322 count--; 00323 } 00324 } 00325 } 00326 00327 /** 00328 * @} 00329 */ 00330 00331 #if (STM32H7_DEV_ID == 0x450UL) 00332 /** @addtogroup UTILS_EF_SYSTEM 00333 * @brief System Configuration functions 00334 * 00335 @verbatim 00336 =============================================================================== 00337 ##### System Configuration functions ##### 00338 =============================================================================== 00339 [..] 00340 System, AHB and APB buses clocks configuration 00341 00342 (+) The maximum frequency of the SYSCLK is 480 MHz(*) and HCLK is 240 MHz. 00343 (+) The maximum frequency of the PCLK1, PCLK2, PCLK3 and PCLK4 is 120 MHz. 00344 @endverbatim 00345 @internal 00346 Depending on the device voltage range, the maximum frequency should be 00347 adapted accordingly: 00348 (++) +----------------------------------------------------------------------------+ 00349 (++) | Wait states | HCLK clock frequency (MHz) | 00350 (++) | |-----------------------------------------------------------| 00351 (++) | (Latency) | voltage range 1 | voltage range 2 | voltage range 3 | 00352 (++) | | 1.15V - 1.26V | 1.05V - 1.15V | 0.95V - 1.05V | 00353 (++) |----------------|-------------------|-------------------|-------------------| 00354 (++) |0WS(1CPU cycle) | 0 < HCLK <= 70 | 0 < HCLK <= 55 | 0 < HCLK <= 45 | 00355 (++) |----------------|-------------------|-------------------|-------------------| 00356 (++) |1WS(2CPU cycle) | 70 < HCLK <= 140 | 55 < HCLK <= 110 | 45 < HCLK <= 90 | 00357 (++) |----------------|-------------------|-------------------|-------------------| 00358 (++) |2WS(3CPU cycle) | 140 < HCLK <= 240 | 110 < HCLK <= 165 | 90 < HCLK <= 135 | 00359 (++) |----------------|-------------------|-------------------|-------------------| 00360 (++) |3WS(4CPU cycle) | -- | 165 < HCLK <= 220 | 135 < HCLK <= 180 | 00361 (++) |----------------|-------------------|-------------------|-------------------| 00362 (++) |4WS(5CPU cycle) | -- | -- | 180 < HCLK <= 225 | 00363 (++) +----------------------------------------------------------------------------+ 00364 00365 (*) : For stm32h74xxx and stm32h75xxx family lines and requires the board to be connected on LDO regulator not SMPS, 400MHZ otherwise. 00366 @endinternal 00367 * @{ 00368 */ 00369 00370 #elif (STM32H7_DEV_ID == 0x480UL) 00371 /** @addtogroup UTILS_EF_SYSTEM 00372 * @brief System Configuration functions 00373 * 00374 @verbatim 00375 =============================================================================== 00376 ##### System Configuration functions ##### 00377 =============================================================================== 00378 [..] 00379 System, AHB and APB buses clocks configuration 00380 00381 (+) The maximum frequency of the SYSCLK is 280 MHz and HCLK is 280 MHz. 00382 (+) The maximum frequency of the PCLK1, PCLK2, PCLK3 and PCLK4 is 140 MHz. 00383 @endverbatim 00384 @internal 00385 Depending on the device voltage range, the maximum frequency should be 00386 adapted accordingly: 00387 (++) +------------------------------------------------------------------------------------------------+ 00388 (++) | Wait states | HCLK clock frequency (MHz) | 00389 (++) | |-------------------------------------------------------------------------------| 00390 (++) | (Latency) | voltage range 0 | voltage range 1 | voltage range 2 | voltage range 3 | 00391 (++) | | 1.26V - 1.35V | 1.15V - 1.26V | 1.05V - 1.15V | 0.95V - 1.05V | 00392 (++) |----------------|-------------------|-------------------|-------------------|-------------------| 00393 (++) |0WS(1CPU cycle) | 0 < HCLK <= 44 | 0 < HCLK <= 42 | 0 < HCLK <= 34 | 0 < HCLK <= 22 | 00394 (++) |----------------|-------------------|-------------------|-------------------|-------------------| 00395 (++) |1WS(2CPU cycle) | 44 < HCLK <= 88 | 42 < HCLK <= 84 | 34 < HCLK <= 68 | 22 < HCLK <= 44 | 00396 (++) |----------------|-------------------|-------------------|-------------------|-------------------| 00397 (++) |2WS(3CPU cycle) | 88 < HCLK <= 132 | 84 < HCLK <= 126 | 68 < HCLK <= 102 | 44 < HCLK <= 66 | 00398 (++) |----------------|-------------------|-------------------|-------------------|-------------------| 00399 (++) |3WS(4CPU cycle) | 132 < HCLK <= 176 | 126 < HCLK <= 168 | 102 < HCLK <= 136 | 66 < HCLK <= 88 | 00400 (++) |----------------|-------------------|-------------------|-------------------|-------------------| 00401 (++) |4WS(5CPU cycle) | 176 < HCLK <= 220 | 168 < HCLK <= 210 | 136 < HCLK <= 160 | -- | 00402 (++) +------------------------------------------------------------------------------------------------+ 00403 (++) |5WS(6CPU cycle) | 220 < HCLK <= 264 | 210 < HCLK <= 225 | -- | -- | 00404 (++) +------------------------------------------------------------------------------------------------+ 00405 (++) |6WS(7CPU cycle) | 264 < HCLK <= 280 | -- | -- | -- | 00406 (++) +------------------------------------------------------------------------------------------------+ 00407 (++) |7WS(8CPU cycle) | -- | -- | -- | -- | 00408 (++) +------------------------------------------------------------------------------------------------+ 00409 00410 @endinternal 00411 * @{ 00412 */ 00413 00414 #elif (STM32H7_DEV_ID == 0x483UL) 00415 /** @addtogroup UTILS_EF_SYSTEM 00416 * @brief System Configuration functions 00417 * 00418 @verbatim 00419 =============================================================================== 00420 ##### System Configuration functions ##### 00421 =============================================================================== 00422 [..] 00423 System, AHB and APB buses clocks configuration 00424 00425 (+) The maximum frequency of the SYSCLK is 550 MHz(*) and HCLK is 275 MHz. 00426 (+) The maximum frequency of the PCLK1, PCLK2, PCLK3 and PCLK4 is 137.5 MHz. 00427 @endverbatim 00428 @internal 00429 Depending on the device voltage range, the maximum frequency should be 00430 adapted accordingly: 00431 (++) +------------------------------------------------------------------------------------------------+ 00432 (++) | Wait states | HCLK clock frequency (MHz) | 00433 (++) | |-------------------------------------------------------------------------------| 00434 (++) | (Latency) | voltage range 0 | voltage range 1 | voltage range 2 | voltage range 3 | 00435 (++) | | 1.26V - 1.40V | 1.15V - 1.26V | 1.05V - 1.15V | 0.95V - 1.05V | 00436 (++) |----------------|-------------------|-------------------|-------------------|-------------------| 00437 (++) |0WS(1CPU cycle) | 0 < HCLK <= 70 | 0 < HCLK <= 67 | 0 < HCLK <= 50 | 0 < HCLK <= 35 | 00438 (++) |----------------|-------------------|-------------------|-------------------|-------------------| 00439 (++) |1WS(2CPU cycle) | 70 < HCLK <= 140 | 67 < HCLK <= 133 | 50 < HCLK <= 100 | 35 < HCLK <= 70 | 00440 (++) |----------------|-------------------|-------------------|-------------------|-------------------| 00441 (++) |2WS(3CPU cycle) | 140 < HCLK <= 210 | 133 < HCLK <= 200 | 100 < HCLK <= 150 | 70 < HCLK <= 85 | 00442 (++) |----------------|-------------------|-------------------|-------------------|-------------------| 00443 (++) |3WS(4CPU cycle) | 210 < HCLK <= 275 | -- | -- | -- | 00444 (++) +----------------|-------------------|-------------------|-------------------|-------------------| 00445 00446 (*) : For stm32h72xxx and stm32h73xxx family lines and requires to enable the CPU_FREQ_BOOST flash option byte, 520MHZ otherwise. 00447 @endinternal 00448 * @{ 00449 */ 00450 #endif /* STM32H7_DEV_ID == 0x450UL */ 00451 00452 #if defined (DUAL_CORE) 00453 /** 00454 * @brief This function sets directly SystemCoreClock CMSIS variable. 00455 * @note Variable can be calculated also through SystemCoreClockUpdate function. 00456 * @param CPU_Frequency Core frequency in Hz 00457 * @note CPU_Frequency can be calculated thanks to RCC helper macro or function 00458 * @ref LL_RCC_GetSystemClocksFreq 00459 * LL_RCC_GetSystemClocksFreq() is used to calculate the CM7 clock frequency 00460 * and __LL_RCC_CALC_HCLK_FREQ is used to calculate the CM4 clock frequency. 00461 * @retval None 00462 */ 00463 #else 00464 /** 00465 * @brief This function sets directly SystemCoreClock CMSIS variable. 00466 * @note Variable can be calculated also through SystemCoreClockUpdate function. 00467 * @param CPU_Frequency Core frequency in Hz 00468 * @note CPU_Frequency can be calculated thanks to RCC helper macro or function 00469 * @ref LL_RCC_GetSystemClocksFreq 00470 * @retval None 00471 */ 00472 #endif /* DUAL_CORE */ 00473 void LL_SetSystemCoreClock(uint32_t CPU_Frequency) 00474 { 00475 /* HCLK clock frequency */ 00476 SystemCoreClock = CPU_Frequency; 00477 } 00478 00479 /** 00480 * @brief This function configures system clock at maximum frequency with HSI as clock source of the PLL 00481 * @note The application need to ensure that PLL is disabled. 00482 * @note Function is based on the following formula: 00483 * - PLL output frequency = (((HSI frequency / PLLM) * PLLN) / PLLP) 00484 * - PLLM: ensure that the VCO input frequency ranges from 1 to 16 MHz (PLLVCO_input = HSI frequency / PLLM) 00485 * - PLLN: ensure that the VCO output frequency is between 150 and 836 MHz or 128 to 560 MHz(***) (PLLVCO_output = PLLVCO_input * PLLN) 00486 * - PLLP: ensure that max frequency at 550000000 Hz(*), 480000000 Hz(**) or 280000000 Hz(***) is reach (PLLVCO_output / PLLP) 00487 * @param UTILS_PLLInitStruct pointer to a @ref LL_UTILS_PLLInitTypeDef structure that contains 00488 * the configuration information for the PLL. 00489 * @param UTILS_ClkInitStruct pointer to a @ref LL_UTILS_ClkInitTypeDef structure that contains 00490 * the configuration information for the BUS prescalers. 00491 * @retval An ErrorStatus enumeration value: 00492 * - SUCCESS: Max frequency configuration done 00493 * - ERROR: Max frequency configuration not done 00494 * 00495 * (*) : For stm32h72xxx and stm32h73xxx family lines and requires to enable the CPU_FREQ_BOOST flash option byte, 520MHZ otherwise. 00496 * (**) : For stm32h74xxx and stm32h75xxx family lines and requires the board to be connected on LDO regulator not SMPS, 400MHZ otherwise. 00497 * (***): For stm32h7a3xx, stm32h7b3xx and stm32h7b0xx family lines. 00498 * 00499 */ 00500 ErrorStatus LL_PLL_ConfigSystemClock_HSI(LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct, 00501 LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct) 00502 { 00503 ErrorStatus status; 00504 #ifdef USE_FULL_ASSERT 00505 uint32_t vcoinput_freq, vcooutput_freq; 00506 #endif 00507 uint32_t pllfreq, hsi_clk; 00508 00509 /* Check the parameters */ 00510 assert_param(IS_LL_UTILS_PLLM_VALUE(UTILS_PLLInitStruct->PLLM)); 00511 assert_param(IS_LL_UTILS_PLLN_VALUE(UTILS_PLLInitStruct->PLLN)); 00512 assert_param(IS_LL_UTILS_PLLP_VALUE(UTILS_PLLInitStruct->PLLP)); 00513 assert_param(IS_LL_UTILS_FRACN_VALUE(UTILS_PLLInitStruct->FRACN)); 00514 00515 hsi_clk = (HSI_VALUE >> (LL_RCC_HSI_GetDivider() >> RCC_CR_HSIDIV_Pos)); 00516 00517 /* Check VCO Input frequency */ 00518 #ifdef USE_FULL_ASSERT 00519 vcoinput_freq = hsi_clk / UTILS_PLLInitStruct->PLLM; 00520 #endif 00521 assert_param(IS_LL_UTILS_PLLVCO_INPUT(vcoinput_freq, UTILS_PLLInitStruct->VCO_Input)); 00522 00523 /* Check VCO Output frequency */ 00524 #ifdef USE_FULL_ASSERT 00525 vcooutput_freq = LL_RCC_CalcPLLClockFreq(hsi_clk, UTILS_PLLInitStruct->PLLM, UTILS_PLLInitStruct->PLLN, UTILS_PLLInitStruct->FRACN, 1UL); 00526 #endif 00527 assert_param(IS_LL_UTILS_PLLVCO_OUTPUT(vcooutput_freq, UTILS_PLLInitStruct->VCO_Output)); 00528 00529 /* Check VCO Input ranges */ 00530 assert_param(IS_LL_UTILS_CHECK_VCO_RANGES(UTILS_PLLInitStruct->VCO_Input, UTILS_PLLInitStruct->VCO_Output)); 00531 00532 /* Check if one of the PLL is enabled */ 00533 if(UTILS_IsPLLsReady() == SUCCESS) 00534 { 00535 /* Calculate the new PLL output frequency */ 00536 pllfreq = UTILS_GetPLLOutputFrequency(hsi_clk, UTILS_PLLInitStruct); 00537 00538 /* Enable HSI if not enabled */ 00539 if(LL_RCC_HSI_IsReady() != 1U) 00540 { 00541 LL_RCC_HSI_Enable(); 00542 while (LL_RCC_HSI_IsReady() != 1U) 00543 { 00544 /* Wait for HSI ready */ 00545 } 00546 } 00547 00548 /* Configure PLL */ 00549 LL_RCC_PLL1P_Enable(); 00550 LL_RCC_PLL1FRACN_Enable(); 00551 LL_RCC_PLL_SetSource(LL_RCC_PLLSOURCE_HSI); 00552 LL_RCC_PLL1_SetVCOInputRange(UTILS_PLLInitStruct->VCO_Input); 00553 LL_RCC_PLL1_SetVCOOutputRange(UTILS_PLLInitStruct->VCO_Output); 00554 LL_RCC_PLL1_SetM(UTILS_PLLInitStruct->PLLM); 00555 LL_RCC_PLL1_SetN(UTILS_PLLInitStruct->PLLN); 00556 LL_RCC_PLL1_SetP(UTILS_PLLInitStruct->PLLP); 00557 LL_RCC_PLL1_SetFRACN(UTILS_PLLInitStruct->FRACN); 00558 00559 /* Enable PLL and switch system clock to PLL */ 00560 status = UTILS_EnablePLLAndSwitchSystem(pllfreq, UTILS_ClkInitStruct); 00561 } 00562 else 00563 { 00564 /* Current PLL configuration cannot be modified */ 00565 status = ERROR; 00566 } 00567 00568 return status; 00569 } 00570 00571 /** 00572 * @brief This function configures system clock with HSE as clock source of the PLL 00573 * @note The application need to ensure that PLL is disabled. 00574 * @note Function is based on the following formula: 00575 * - PLL output frequency = (((HSE frequency / PLLM) * PLLN) / PLLP) 00576 * - PLLM: ensure that the VCO input frequency ranges from 0.95 to 2.10 MHz (PLLVCO_input = HSE frequency / PLLM) 00577 * - PLLN: ensure that the VCO output frequency is between 150 and 836 MHz or 128 to 560 MHz(***) (PLLVCO_output = PLLVCO_input * PLLN) 00578 * - PLLP: ensure that max frequency at 550000000 Hz(*), 480000000 Hz(**) or 280000000 Hz(***) is reached (PLLVCO_output / PLLP) 00579 * @param HSEFrequency Value between Min_Data = 4000000 and Max_Data = 48000000 00580 * @param HSEBypass This parameter can be one of the following values: 00581 * @arg @ref LL_UTILS_HSEBYPASS_ON 00582 * @arg @ref LL_UTILS_HSEBYPASS_OFF 00583 * @param UTILS_PLLInitStruct pointer to a @ref LL_UTILS_PLLInitTypeDef structure that contains 00584 * the configuration information for the PLL. 00585 * @param UTILS_ClkInitStruct pointer to a @ref LL_UTILS_ClkInitTypeDef structure that contains 00586 * the configuration information for the BUS prescalers. 00587 * @retval An ErrorStatus enumeration value: 00588 * - SUCCESS: Max frequency configuration done 00589 * - ERROR: Max frequency configuration not done 00590 * 00591 * (*) : For stm32h72xxx and stm32h73xxx family lines and requires to enable the CPU_FREQ_BOOST flash option byte, 520MHZ otherwise. 00592 * (**) : For stm32h74xxx and stm32h75xxx family lines and requires the board to be connected on LDO regulator not SMPS, 400MHZ otherwise. 00593 * (***): For stm32h7a3xx, stm32h7b3xx and stm32h7b0xx family lines. 00594 * 00595 */ 00596 ErrorStatus LL_PLL_ConfigSystemClock_HSE(uint32_t HSEFrequency, uint32_t HSEBypass, 00597 LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct) 00598 { 00599 ErrorStatus status; 00600 #ifdef USE_FULL_ASSERT 00601 uint32_t vcoinput_freq, vcooutput_freq; 00602 #endif 00603 uint32_t pllfreq; 00604 00605 /* Check the parameters */ 00606 assert_param(IS_LL_UTILS_PLLM_VALUE(UTILS_PLLInitStruct->PLLM)); 00607 assert_param(IS_LL_UTILS_PLLN_VALUE(UTILS_PLLInitStruct->PLLN)); 00608 assert_param(IS_LL_UTILS_PLLP_VALUE(UTILS_PLLInitStruct->PLLP)); 00609 assert_param(IS_LL_UTILS_FRACN_VALUE(UTILS_PLLInitStruct->FRACN)); 00610 assert_param(IS_LL_UTILS_HSE_FREQUENCY(HSEFrequency)); 00611 assert_param(IS_LL_UTILS_HSE_BYPASS(HSEBypass)); 00612 00613 /* Check VCO Input frequency */ 00614 #ifdef USE_FULL_ASSERT 00615 vcoinput_freq = HSEFrequency / UTILS_PLLInitStruct->PLLM; 00616 #endif 00617 assert_param(IS_LL_UTILS_PLLVCO_INPUT(vcoinput_freq, UTILS_PLLInitStruct->VCO_Input)); 00618 00619 /* Check VCO output frequency */ 00620 #ifdef USE_FULL_ASSERT 00621 vcooutput_freq = LL_RCC_CalcPLLClockFreq(HSEFrequency, UTILS_PLLInitStruct->PLLM, UTILS_PLLInitStruct->PLLN, UTILS_PLLInitStruct->FRACN, 1U); 00622 #endif 00623 assert_param(IS_LL_UTILS_PLLVCO_OUTPUT(vcooutput_freq, UTILS_PLLInitStruct->VCO_Output)); 00624 00625 /* Check VCO Input/output ranges compatibility */ 00626 assert_param(IS_LL_UTILS_CHECK_VCO_RANGES(UTILS_PLLInitStruct->VCO_Input, UTILS_PLLInitStruct->VCO_Output)); 00627 00628 /* Check if one of the PLL is enabled */ 00629 if(UTILS_IsPLLsReady() == SUCCESS) 00630 { 00631 /* Calculate the new PLL output frequency */ 00632 pllfreq = UTILS_GetPLLOutputFrequency(HSEFrequency, UTILS_PLLInitStruct); 00633 00634 /* Enable HSE if not enabled */ 00635 if(LL_RCC_HSE_IsReady() != 1U) 00636 { 00637 /* Check if need to enable HSE bypass feature or not */ 00638 if(HSEBypass == LL_UTILS_HSEBYPASS_ON) 00639 { 00640 LL_RCC_HSE_EnableBypass(); 00641 } 00642 else 00643 { 00644 LL_RCC_HSE_DisableBypass(); 00645 } 00646 00647 /* Enable HSE */ 00648 LL_RCC_HSE_Enable(); 00649 while (LL_RCC_HSE_IsReady() != 1U) 00650 { 00651 /* Wait for HSE ready */ 00652 } 00653 } 00654 00655 /* Configure PLL */ 00656 LL_RCC_PLL1P_Enable(); 00657 LL_RCC_PLL1FRACN_Enable(); 00658 LL_RCC_PLL_SetSource(LL_RCC_PLLSOURCE_HSE); 00659 LL_RCC_PLL1_SetVCOInputRange(UTILS_PLLInitStruct->VCO_Input); 00660 LL_RCC_PLL1_SetVCOOutputRange(UTILS_PLLInitStruct->VCO_Output); 00661 LL_RCC_PLL1_SetM(UTILS_PLLInitStruct->PLLM); 00662 LL_RCC_PLL1_SetN(UTILS_PLLInitStruct->PLLN); 00663 LL_RCC_PLL1_SetP(UTILS_PLLInitStruct->PLLP); 00664 LL_RCC_PLL1_SetFRACN(UTILS_PLLInitStruct->FRACN); 00665 00666 /* Enable PLL and switch system clock to PLL */ 00667 status = UTILS_EnablePLLAndSwitchSystem(pllfreq, UTILS_ClkInitStruct); 00668 } 00669 else 00670 { 00671 /* Current PLL configuration cannot be modified */ 00672 status = ERROR; 00673 } 00674 00675 return status; 00676 } 00677 00678 /** 00679 * @} 00680 */ 00681 00682 /** 00683 * @brief Update number of Flash wait states in line with new frequency and current 00684 voltage range. 00685 * @param HCLK_Frequency HCLK frequency 00686 * @retval An ErrorStatus enumeration value: 00687 * - SUCCESS: Latency has been modified 00688 * - ERROR: Latency cannot be modified 00689 */ 00690 ErrorStatus LL_SetFlashLatency(uint32_t HCLK_Frequency) 00691 { 00692 ErrorStatus status = SUCCESS; 00693 uint32_t timeout; 00694 uint32_t getlatency; 00695 uint32_t latency = LL_FLASH_LATENCY_0; /* default value 0WS */ 00696 00697 00698 00699 /* Frequency cannot be equal to 0 */ 00700 if (HCLK_Frequency == 0U) 00701 { 00702 status = ERROR; 00703 } 00704 else 00705 { 00706 #if (STM32H7_DEV_ID == 0x480UL) || (STM32H7_DEV_ID == 0x483UL) 00707 if(LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE0) 00708 { 00709 #if (STM32H7_DEV_ID == 0x480UL) 00710 if((HCLK_Frequency > UTILS_SCALE0_LATENCY5_FREQ) && (HCLK_Frequency <= UTILS_SCALE0_LATENCY6_FREQ)) 00711 { 00712 /* 264 < HCLK <= 280 => 6WS (7 CPU cycles) */ 00713 latency = LL_FLASH_LATENCY_6; 00714 } 00715 else if((HCLK_Frequency > UTILS_SCALE0_LATENCY4_FREQ) && (HCLK_Frequency <= UTILS_SCALE0_LATENCY5_FREQ)) 00716 { 00717 /* 220 < HCLK <= 264 => 5WS (6 CPU cycles) */ 00718 latency = LL_FLASH_LATENCY_5; 00719 } 00720 else if((HCLK_Frequency > UTILS_SCALE0_LATENCY3_FREQ) && (HCLK_Frequency <= UTILS_SCALE0_LATENCY4_FREQ)) 00721 { 00722 /* 176 < HCLK <= 220 => 4WS (5 CPU cycles) */ 00723 latency = LL_FLASH_LATENCY_4; 00724 } 00725 else if((HCLK_Frequency > UTILS_SCALE0_LATENCY2_FREQ) && (HCLK_Frequency <= UTILS_SCALE0_LATENCY3_FREQ)) 00726 #elif (STM32H7_DEV_ID == 0x483UL) 00727 if((HCLK_Frequency > UTILS_SCALE0_LATENCY2_FREQ) && (HCLK_Frequency <= UTILS_SCALE0_LATENCY3_FREQ)) 00728 #endif /* STM32H7_DEV_ID == 0x480UL */ 00729 { 00730 /* 132 < HCLK <= 176 => 3WS (4 CPU cycles) */ 00731 latency = LL_FLASH_LATENCY_3; 00732 } 00733 else if((HCLK_Frequency > UTILS_SCALE0_LATENCY1_FREQ) && (HCLK_Frequency <= UTILS_SCALE0_LATENCY2_FREQ)) 00734 { 00735 /* 88 < HCLK <= 132 => 2WS (3 CPU cycles) */ 00736 latency = LL_FLASH_LATENCY_2; 00737 } 00738 else if((HCLK_Frequency > UTILS_SCALE0_LATENCY0_FREQ) && (HCLK_Frequency <= UTILS_SCALE0_LATENCY1_FREQ)) 00739 { 00740 /* 44 < HCLK <= 88 => 1WS (2 CPU cycles) */ 00741 latency = LL_FLASH_LATENCY_1; 00742 } 00743 else if(HCLK_Frequency <= UTILS_SCALE0_LATENCY0_FREQ) 00744 { 00745 /* HCLK <= 44 => 0WS (1 CPU cycles) : Do nothing keep latency to default LL_FLASH_LATENCY_0 */ 00746 } 00747 else 00748 { 00749 status = ERROR; 00750 } 00751 } 00752 #if (STM32H7_DEV_ID == 0x480UL) 00753 else if(LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE1) 00754 { 00755 if((HCLK_Frequency > UTILS_SCALE1_LATENCY4_FREQ) && (HCLK_Frequency <= UTILS_SCALE1_LATENCY5_FREQ)) 00756 { 00757 /* 210 < HCLK <= 225 => 5WS (6 CPU cycles) */ 00758 latency = LL_FLASH_LATENCY_5; 00759 } 00760 else if((HCLK_Frequency > UTILS_SCALE1_LATENCY3_FREQ) && (HCLK_Frequency <= UTILS_SCALE1_LATENCY4_FREQ)) 00761 { 00762 /* 168 < HCLK <= 210 => 4WS (5 CPU cycles) */ 00763 latency = LL_FLASH_LATENCY_4; 00764 } 00765 else if((HCLK_Frequency > UTILS_SCALE1_LATENCY2_FREQ) && (HCLK_Frequency <= UTILS_SCALE1_LATENCY3_FREQ)) 00766 { 00767 /* 126 < HCLK <= 168 => 3WS (4 CPU cycles) */ 00768 latency = LL_FLASH_LATENCY_3; 00769 } 00770 else if((HCLK_Frequency > UTILS_SCALE1_LATENCY1_FREQ) && (HCLK_Frequency <= UTILS_SCALE1_LATENCY2_FREQ)) 00771 #else 00772 if(LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE1) 00773 { 00774 if((HCLK_Frequency > UTILS_SCALE1_LATENCY1_FREQ) && (HCLK_Frequency <= UTILS_SCALE1_LATENCY2_FREQ)) 00775 #endif /* STM32H7_DEV_ID == 0x480UL */ 00776 #else 00777 if(LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE1) 00778 { 00779 if((HCLK_Frequency > UTILS_SCALE1_LATENCY1_FREQ) && (HCLK_Frequency <= UTILS_SCALE1_LATENCY2_FREQ)) 00780 #endif /* STM32H7_DEV_ID == 0x480UL || STM32H7_DEV_ID == 0x483UL */ 00781 { 00782 /* 140 < HCLK <= 210 => 2WS (3 CPU cycles) */ 00783 latency = LL_FLASH_LATENCY_2; 00784 } 00785 else if((HCLK_Frequency > UTILS_SCALE1_LATENCY0_FREQ) && (HCLK_Frequency <= UTILS_SCALE1_LATENCY1_FREQ)) 00786 { 00787 /* 70 < HCLK <= 140 => 1WS (2 CPU cycles) */ 00788 latency = LL_FLASH_LATENCY_1; 00789 } 00790 else if(HCLK_Frequency <= UTILS_SCALE1_LATENCY0_FREQ) 00791 { 00792 /* HCLK <= 70 => 0WS (1 CPU cycles) : Do nothing keep latency to default LL_FLASH_LATENCY_0 */ 00793 } 00794 else 00795 { 00796 status = ERROR; 00797 } 00798 } 00799 else if(LL_PWR_GetRegulVoltageScaling() == LL_PWR_REGU_VOLTAGE_SCALE2) 00800 { 00801 #if (STM32H7_DEV_ID == 0x480UL) || (STM32H7_DEV_ID == 0x450UL) 00802 #if (STM32H7_DEV_ID == 0x480UL) 00803 if((HCLK_Frequency > UTILS_SCALE2_LATENCY3_FREQ) && (HCLK_Frequency <= UTILS_SCALE2_LATENCY4_FREQ)) 00804 { 00805 /* 136 < HCLK <= 160 => 4WS (5 CPU cycles) */ 00806 latency = LL_FLASH_LATENCY_4; 00807 } 00808 else if((HCLK_Frequency > UTILS_SCALE2_LATENCY2_FREQ) && (HCLK_Frequency <= UTILS_SCALE2_LATENCY3_FREQ)) 00809 #else 00810 if((HCLK_Frequency > UTILS_SCALE2_LATENCY2_FREQ) && (HCLK_Frequency <= UTILS_SCALE2_LATENCY3_FREQ)) 00811 #endif /* STM32H7_DEV_ID == 0x480UL */ 00812 { 00813 /* 165 < HCLK <= 220 => 3WS (4 CPU cycles) */ 00814 latency = LL_FLASH_LATENCY_3; 00815 } 00816 else if((HCLK_Frequency > UTILS_SCALE2_LATENCY1_FREQ) && (HCLK_Frequency <= UTILS_SCALE2_LATENCY2_FREQ)) 00817 #else 00818 if((HCLK_Frequency > UTILS_SCALE2_LATENCY1_FREQ) && (HCLK_Frequency <= UTILS_SCALE2_LATENCY2_FREQ)) 00819 #endif /* STM32H7_DEV_ID == 0x480UL || STM32H7_DEV_ID == 0x450UL */ 00820 { 00821 /* 110 < HCLK <= 165 => 2WS (3 CPU cycles) */ 00822 latency = LL_FLASH_LATENCY_2; 00823 } 00824 else if((HCLK_Frequency > UTILS_SCALE2_LATENCY0_FREQ) && (HCLK_Frequency <= UTILS_SCALE2_LATENCY1_FREQ)) 00825 { 00826 /* 55 < HCLK <= 110 => 1WS (2 CPU cycles) */ 00827 latency = LL_FLASH_LATENCY_1; 00828 } 00829 else if(HCLK_Frequency <= UTILS_SCALE2_LATENCY0_FREQ) 00830 { 00831 /* HCLK <= 55 => 0WS (1 CPU cycles) : Do nothing keep latency to default LL_FLASH_LATENCY_0 */ 00832 } 00833 else 00834 { 00835 status = ERROR; 00836 } 00837 } 00838 else /* Scale 3 */ 00839 { 00840 #if (STM32H7_DEV_ID == 0x450UL) || (STM32H7_DEV_ID == 0x480UL) 00841 #if (STM32H7_DEV_ID == 0x450UL) 00842 if((HCLK_Frequency > UTILS_SCALE3_LATENCY3_FREQ) && (HCLK_Frequency <= UTILS_SCALE3_LATENCY4_FREQ)) 00843 { 00844 /* 180 < HCLK <= 225 => 4WS (5 CPU cycles) */ 00845 latency = LL_FLASH_LATENCY_4; 00846 } 00847 else if((HCLK_Frequency > UTILS_SCALE3_LATENCY2_FREQ) && (HCLK_Frequency <= UTILS_SCALE3_LATENCY3_FREQ)) 00848 #else 00849 if((HCLK_Frequency > UTILS_SCALE3_LATENCY2_FREQ) && (HCLK_Frequency <= UTILS_SCALE3_LATENCY3_FREQ)) 00850 #endif /*STM32H7_DEV_ID == 0x450UL*/ 00851 { 00852 /* 135 < HCLK <= 180 => 3WS (4 CPU cycles) */ 00853 latency = LL_FLASH_LATENCY_3; 00854 } 00855 else if((HCLK_Frequency > UTILS_SCALE3_LATENCY1_FREQ) && (HCLK_Frequency <= UTILS_SCALE3_LATENCY2_FREQ)) 00856 #else 00857 if((HCLK_Frequency > UTILS_SCALE3_LATENCY1_FREQ) && (HCLK_Frequency <= UTILS_SCALE3_LATENCY2_FREQ)) 00858 #endif /* STM32H7_DEV_ID == 0x450UL || STM32H7_DEV_ID == 0x480UL */ 00859 { 00860 /* 90 < HCLK <= 135 => 2WS (3 CPU cycles) */ 00861 latency = LL_FLASH_LATENCY_2; 00862 } 00863 else if((HCLK_Frequency > UTILS_SCALE3_LATENCY0_FREQ) && (HCLK_Frequency <= UTILS_SCALE3_LATENCY1_FREQ)) 00864 { 00865 /* 45 < HCLK <= 90 => 1WS (2 CPU cycles) */ 00866 latency = LL_FLASH_LATENCY_1; 00867 } 00868 else if(HCLK_Frequency <= UTILS_SCALE3_LATENCY0_FREQ) 00869 { 00870 /* HCLK <= 45 => 0WS (1 CPU cycles) : Do nothing keep latency to default LL_FLASH_LATENCY_0 */ 00871 } 00872 else 00873 { 00874 status = ERROR; 00875 } 00876 } 00877 00878 if(status == SUCCESS) 00879 { 00880 LL_FLASH_SetLatency(latency); 00881 00882 /* Check that the new number of wait states is taken into account to access the Flash 00883 memory by reading the FLASH_ACR register */ 00884 timeout = 2; 00885 do 00886 { 00887 /* Wait for Flash latency to be updated */ 00888 getlatency = LL_FLASH_GetLatency(); 00889 timeout--; 00890 } while ((getlatency != latency) && (timeout > 0U)); 00891 00892 if(getlatency != latency) 00893 { 00894 status = ERROR; 00895 } 00896 } 00897 } 00898 00899 return status; 00900 } 00901 00902 00903 /** 00904 * @} 00905 */ 00906 00907 /** @addtogroup UTILS_LL_Private_Functions 00908 * @{ 00909 */ 00910 00911 00912 /** 00913 * @brief Function to check that PLL can be modified 00914 * @param PLL_InputFrequency PLL input frequency (in Hz) 00915 * @param UTILS_PLLInitStruct pointer to a @ref LL_UTILS_PLLInitTypeDef structure that contains 00916 * the configuration information for the PLL. 00917 * @retval PLL output frequency (in Hz) 00918 */ 00919 static uint32_t UTILS_GetPLLOutputFrequency(uint32_t PLL_InputFrequency, LL_UTILS_PLLInitTypeDef *UTILS_PLLInitStruct) 00920 { 00921 uint32_t pllfreq; 00922 00923 /* Check the parameters */ 00924 assert_param(IS_LL_UTILS_PLLM_VALUE(UTILS_PLLInitStruct->PLLM)); 00925 assert_param(IS_LL_UTILS_PLLN_VALUE(UTILS_PLLInitStruct->PLLN)); 00926 assert_param(IS_LL_UTILS_PLLP_VALUE(UTILS_PLLInitStruct->PLLP)); 00927 assert_param(IS_LL_UTILS_FRACN_VALUE(UTILS_PLLInitStruct->FRACN)); 00928 00929 pllfreq = LL_RCC_CalcPLLClockFreq(PLL_InputFrequency, UTILS_PLLInitStruct->PLLM, UTILS_PLLInitStruct->PLLN, UTILS_PLLInitStruct->FRACN, UTILS_PLLInitStruct->PLLP); 00930 00931 return pllfreq; 00932 } 00933 00934 /** 00935 * @brief Check that all PLLs are ready therefore configuration can be done 00936 * @retval An ErrorStatus enumeration value: 00937 * - SUCCESS: All PLLs are ready so configuration can be done 00938 * - ERROR: One PLL at least is busy 00939 */ 00940 static ErrorStatus UTILS_IsPLLsReady(void) 00941 { 00942 ErrorStatus status = SUCCESS; 00943 00944 /* Check if one of the PLL1 is busy */ 00945 if(LL_RCC_PLL1_IsReady() != 0U) 00946 { 00947 /* PLL1 configuration cannot be done */ 00948 status = ERROR; 00949 } 00950 00951 /* Check if one of the PLL2 is busy */ 00952 if(LL_RCC_PLL2_IsReady() != 0U) 00953 { 00954 /* PLL2 configuration cannot be done */ 00955 status = ERROR; 00956 } 00957 00958 /* Check if one of the PLL3 is busy */ 00959 if(LL_RCC_PLL3_IsReady() != 0U) 00960 { 00961 /* PLL3 configuration cannot be done */ 00962 status = ERROR; 00963 } 00964 00965 return status; 00966 } 00967 00968 /** 00969 * @brief Function to enable PLL and switch system clock to PLL 00970 * @param SYSCLK_Frequency SYSCLK frequency 00971 * @param UTILS_ClkInitStruct pointer to a @ref LL_UTILS_ClkInitTypeDef structure that contains 00972 * the configuration information for the BUS prescalers. 00973 * @retval An ErrorStatus enumeration value: 00974 * - SUCCESS: No problem to switch system to PLL 00975 * - ERROR: Problem to switch system to PLL 00976 */ 00977 static ErrorStatus UTILS_EnablePLLAndSwitchSystem(uint32_t SYSCLK_Frequency, LL_UTILS_ClkInitTypeDef *UTILS_ClkInitStruct) 00978 { 00979 ErrorStatus status = SUCCESS; 00980 uint32_t new_hclk_frequency; 00981 00982 assert_param(IS_LL_UTILS_SYSCLK_DIV(UTILS_ClkInitStruct->SYSCLKDivider)); 00983 assert_param(IS_LL_UTILS_AHB_DIV(UTILS_ClkInitStruct->AHBCLKDivider)); 00984 assert_param(IS_LL_UTILS_APB1_DIV(UTILS_ClkInitStruct->APB1CLKDivider)); 00985 assert_param(IS_LL_UTILS_APB2_DIV(UTILS_ClkInitStruct->APB2CLKDivider)); 00986 assert_param(IS_LL_UTILS_APB3_DIV(UTILS_ClkInitStruct->APB3CLKDivider)); 00987 assert_param(IS_LL_UTILS_APB4_DIV(UTILS_ClkInitStruct->APB4CLKDivider)); 00988 00989 /* Calculate the new HCLK frequency */ 00990 new_hclk_frequency = LL_RCC_CALC_HCLK_FREQ(SYSCLK_Frequency, UTILS_ClkInitStruct->AHBCLKDivider); 00991 00992 /* Increasing the number of wait states because of higher CPU frequency */ 00993 if (SystemD2Clock < new_hclk_frequency) 00994 { 00995 /* Set FLASH latency to highest latency */ 00996 status = LL_SetFlashLatency(new_hclk_frequency); 00997 } 00998 00999 /* Update system clock configuration */ 01000 if(status == SUCCESS) 01001 { 01002 /* Enable PLL */ 01003 LL_RCC_PLL1_Enable(); 01004 while (LL_RCC_PLL1_IsReady() != 1U) 01005 { 01006 /* Wait for PLL ready */ 01007 } 01008 01009 /* Set All APBxPrescaler to the Highest Divider */ 01010 LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_16); 01011 LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_16); 01012 LL_RCC_SetAPB3Prescaler(LL_RCC_APB3_DIV_16); 01013 LL_RCC_SetAPB4Prescaler(LL_RCC_APB4_DIV_16); 01014 01015 /* Set SYS prescaler*/ 01016 LL_RCC_SetSysPrescaler(UTILS_ClkInitStruct->SYSCLKDivider); 01017 01018 /* Set AHB prescaler*/ 01019 LL_RCC_SetAHBPrescaler(UTILS_ClkInitStruct->AHBCLKDivider); 01020 01021 /* Sysclk activation on the main PLL */ 01022 LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL1); 01023 while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL1) 01024 { 01025 /* Wait for system clock switch to PLL */ 01026 } 01027 01028 /* Set APBn prescaler*/ 01029 LL_RCC_SetAPB1Prescaler(UTILS_ClkInitStruct->APB1CLKDivider); 01030 LL_RCC_SetAPB2Prescaler(UTILS_ClkInitStruct->APB2CLKDivider); 01031 LL_RCC_SetAPB3Prescaler(UTILS_ClkInitStruct->APB3CLKDivider); 01032 LL_RCC_SetAPB4Prescaler(UTILS_ClkInitStruct->APB4CLKDivider); 01033 01034 /* Decreasing the number of wait states because of lower CPU frequency */ 01035 if (SystemD2Clock > new_hclk_frequency) 01036 { 01037 /* Set FLASH latency to lowest latency */ 01038 status = LL_SetFlashLatency(new_hclk_frequency); 01039 } 01040 01041 /* Update the SystemD2Clock global variable */ 01042 #if defined(RCC_D1CFGR_HPRE) 01043 SystemD2Clock = (SYSCLK_Frequency >> ((D1CorePrescTable[(RCC->D1CFGR & RCC_D1CFGR_HPRE)>> RCC_D1CFGR_HPRE_Pos]) & 0x1FU)); 01044 #else 01045 SystemD2Clock = (SYSCLK_Frequency >> ((D1CorePrescTable[(RCC->CDCFGR1 & RCC_CDCFGR1_HPRE)>> RCC_CDCFGR1_HPRE_Pos]) & 0x1FU)); 01046 #endif 01047 01048 /* Update SystemCoreClock variable */ 01049 #if defined(DUAL_CORE) && defined(CORE_CM4) 01050 LL_SetSystemCoreClock(SystemD2Clock); 01051 #else 01052 LL_SetSystemCoreClock(SYSCLK_Frequency); 01053 #endif /* DUAL_CORE && CORE_CM4 */ 01054 01055 } 01056 01057 01058 return status; 01059 } 01060 01061 /** 01062 * @} 01063 */ 01064 01065 /** 01066 * @} 01067 */ 01068 01069 /** 01070 * @} 01071 */ 01072