1 /** 2 ****************************************************************************** 3 * @file stm32wb0x_ll_utils.c 4 * @author MCD Application Team 5 * @brief UTILS LL module driver. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2024 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 /* Includes ------------------------------------------------------------------*/ 19 #include "stm32wb0x_ll_utils.h" 20 #include "stm32wb0x_ll_rcc.h" 21 #include "stm32wb0x_ll_system.h" 22 #include "stm32wb0x_ll_pwr.h" 23 #include "stm32_assert.h" 24 25 /** @addtogroup STM32WB0x_LL_Driver 26 * @{ 27 */ 28 29 /** @addtogroup UTILS_LL 30 * @{ 31 */ 32 33 /* Private types -------------------------------------------------------------*/ 34 /* Private variables ---------------------------------------------------------*/ 35 /* Private constants ---------------------------------------------------------*/ 36 /** @addtogroup UTILS_LL_Private_Constants 37 * @{ 38 */ 39 40 /** 41 * @} 42 */ 43 44 /* Private macros ------------------------------------------------------------*/ 45 /** @addtogroup UTILS_LL_Private_Macros 46 * @{ 47 */ 48 #define IS_LL_UTILS_SYSCLK_DIV(__VALUE__) (((__VALUE__) == LL_RCC_RC64MPLL_DIV_1) \ 49 || ((__VALUE__) == LL_RCC_RC64MPLL_DIV_2) \ 50 || ((__VALUE__) == LL_RCC_RC64MPLL_DIV_4) \ 51 || ((__VALUE__) == LL_RCC_RC64MPLL_DIV_8) \ 52 || ((__VALUE__) == LL_RCC_RC64MPLL_DIV_16) \ 53 || ((__VALUE__) == LL_RCC_RC64MPLL_DIV_32) \ 54 || ((__VALUE__) == LL_RCC_RC64MPLL_DIV_64)) 55 56 #define IS_LL_UTILS_DIRECT_HSE_DIV(__VALUE__) (((__VALUE__) == LL_RCC_DIRECT_HSE_DIV_1) \ 57 || ((__VALUE__) == LL_RCC_DIRECT_HSE_DIV_2) \ 58 || ((__VALUE__) == LL_RCC_DIRECT_HSE_DIV_4) \ 59 || ((__VALUE__) == LL_RCC_DIRECT_HSE_DIV_8) \ 60 || ((__VALUE__) == LL_RCC_DIRECT_HSE_DIV_16) \ 61 || ((__VALUE__) == LL_RCC_DIRECT_HSE_DIV_32)) 62 63 64 #define IS_LL_UTILS_HSE_BYPASS(__STATE__) (((__STATE__) == LL_UTILS_HSEBYPASS_ON) \ 65 || ((__STATE__) == LL_UTILS_HSEBYPASS_OFF)) 66 67 #define countof(a) (sizeof(a) / sizeof(*(a))) 68 /** 69 * @} 70 */ 71 /* Private function prototypes -----------------------------------------------*/ 72 /** @defgroup UTILS_LL_Private_Functions UTILS Private functions 73 * @{ 74 */ 75 76 /** 77 * @} 78 */ 79 80 /* Exported functions --------------------------------------------------------*/ 81 /** @addtogroup UTILS_LL_Exported_Functions 82 * @{ 83 */ 84 85 /** @addtogroup UTILS_LL_EF_DELAY 86 * @{ 87 */ 88 89 /** 90 * @brief This function configures the Cortex-M SysTick source to have 1ms time base. 91 * @note When a RTOS is used, it is recommended to avoid changing the Systick 92 * configuration by calling this function, for a delay use rather osDelay RTOS service. 93 * @param HCLKFrequency SysClk frequency in Hz 94 * @retval None 95 */ 96 LL_Init1msTick(uint32_t HCLKFrequency)97void LL_Init1msTick(uint32_t HCLKFrequency) 98 { 99 /* Use frequency provided in argument */ 100 LL_InitTick(HCLKFrequency, 1000); 101 } 102 103 104 /** 105 * @brief This function provides accurate delay (in milliseconds) based 106 * on SysTick counter flag 107 * @note When a RTOS is used, it is recommended to avoid using blocking delay 108 * and use rather osDelay service. 109 * @note To respect 1ms timebase, user should call @ref LL_Init1msTick function which 110 * will configure Systick to 1ms 111 * @param Delay specifies the delay time length, in milliseconds. 112 * @retval None 113 */ LL_mDelay(uint32_t Delay)114void LL_mDelay(uint32_t Delay) 115 { 116 uint32_t mDelay = Delay; 117 __IO uint32_t tmp = SysTick->CTRL; /* Clear the COUNTFLAG first */ 118 /* Add this code to indicate that local variable is not used */ 119 ((void)tmp); 120 121 /* Add a period to guaranty minimum wait */ 122 if (mDelay < LL_MAX_DELAY) 123 { 124 mDelay++; 125 } 126 127 while (mDelay != 0U) 128 { 129 if ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) != 0U) 130 { 131 mDelay--; 132 } 133 } 134 } 135 136 /** 137 * @} 138 */ 139 140 /** 141 * @brief This function sets the System Core Clock. 142 * @param HCLKFrequency system clock divided factor from HSI64MPLL 143 * This parameter can be one of the following values: 144 * SYSCLK_64M 145 * SYSCLK_32M 146 * SYSCLK_16M 147 * SYSCLK_8M 148 * SYSCLK_4M 149 * SYSCLK_2M 150 * SYSCLK_1M 151 * SYSCLK_DIRECT_HSE 152 * SYSCLK_DIRECT_HSE_DIV2 153 * @retval SUCCESS or error code 154 */ 155 LL_SetSystemCoreClock(uint32_t HCLKFrequency)156void LL_SetSystemCoreClock(uint32_t HCLKFrequency) 157 { 158 /* HCLK clock frequency */ 159 SystemCoreClock = HCLKFrequency; 160 } 161 162 /** 163 * @brief This function return the System Core Clock expressed in Hz. 164 * @retval System Core Clock frequency. 165 */ LL_GetSystemCoreClock(void)166uint32_t LL_GetSystemCoreClock(void) 167 { 168 return SystemCoreClock; 169 } 170 171 172 /** 173 * @} 174 */ 175 176 177 178 /** 179 * @} 180 */ 181 182 /** 183 * @} 184 */ 185