1 /* USER CODE BEGIN Header */ 2 /** 3 ****************************************************************************** 4 * @file scm.h 5 * @author MCD Application Team 6 * @brief Header for scm.c module 7 ****************************************************************************** 8 * @attention 9 * 10 * Copyright (c) 2022 STMicroelectronics. 11 * All rights reserved. 12 * 13 * This software is licensed under terms that can be found in the LICENSE file 14 * in the root directory of this software component. 15 * If no LICENSE file comes with this software, it is provided AS-IS. 16 * 17 ****************************************************************************** 18 */ 19 /* USER CODE END Header */ 20 21 /* Define to prevent recursive inclusion -------------------------------------*/ 22 #ifndef SCM_H 23 #define SCM_H 24 25 /* Includes ------------------------------------------------------------------*/ 26 #include "main.h" 27 28 #if (CFG_SCM_SUPPORTED == 1) 29 #include "stm32wbaxx_hal.h" 30 #include "stm32wbaxx_ll_pwr.h" 31 #include "stm32wbaxx_ll_rcc.h" 32 33 /* Exported types ------------------------------------------------------------*/ 34 typedef enum { 35 NO_CLOCK_CONFIG = 0, 36 HSE_16MHZ, 37 HSE_32MHZ, 38 SYS_PLL, 39 } scm_clockconfig_t; 40 41 typedef enum { 42 LP, 43 RUN, 44 HSE16, 45 HSE32, 46 PLL, 47 } scm_ws_lp_t; 48 49 typedef enum { 50 HSEPRE_DISABLE = 0, 51 HSEPRE_ENABLE 52 } scm_hse_hsepre_t; 53 54 typedef enum { 55 SCM_USER_APP, 56 SCM_USER_LL_FW, 57 SCM_USER_LL_HW_RCO_CLBR, 58 TOTAL_CLIENT_NUM, /* To be at the end of the enum */ 59 } scm_user_id_t; 60 61 typedef enum { 62 NO_PLL, 63 PLL_INTEGER_MODE, 64 PLL_FRACTIONAL_MODE, 65 } scm_pll_mode_t; 66 67 typedef enum { 68 SCM_RADIO_NOT_ACTIVE, 69 SCM_RADIO_ACTIVE, 70 } scm_radio_state_t; 71 72 typedef struct { 73 uint8_t are_pll_params_initialized; 74 scm_pll_mode_t pll_mode; 75 uint32_t PLLM; 76 uint32_t PLLN; 77 uint32_t PLLP; 78 uint32_t PLLQ; 79 uint32_t PLLR; 80 uint32_t PLLFractional; 81 uint32_t AHB5_PLL1_CLKDivider; 82 } scm_pll_config_t; 83 84 typedef struct{ 85 scm_clockconfig_t targeted_clock_freq; 86 uint32_t flash_ws_cfg; 87 uint32_t sram_ws_cfg; 88 scm_pll_config_t pll; 89 } scm_system_clock_t; 90 91 /* Exported constants --------------------------------------------------------*/ 92 /* Exported variables --------------------------------------------------------*/ 93 94 /* Exported macro ------------------------------------------------------------*/ 95 /* Exported functions prototypes ---------------------------------------------*/ 96 97 /** 98 * @brief System Clock Manager init code 99 * @param None 100 * @retval None 101 */ 102 void scm_init(void); 103 104 /** 105 * @brief Setup the system clock source in usable configuration for Connectivity use cases. 106 * Called at startup or out of low power modes. 107 * @param None 108 * @retval None 109 */ 110 void scm_setup(void); 111 112 /** 113 * @brief Configure the PLL mode and parameters before PLL selection as system clock. 114 * @param p_pll_config PLL coniguration to apply 115 * @retval None 116 * @note scm_pll_setconfig to be called before PLL activation (PLL set as system core clock) 117 */ 118 void scm_pll_setconfig(const scm_pll_config_t *p_pll_config); 119 120 /** 121 * @brief Restore system clock configuration when moving out of standby. 122 * @param None 123 * @retval None 124 */ 125 void scm_standbyexit(void); 126 127 /** 128 * @brief Configure the PLL for switching fractional parameters on the fly. 129 * @param pll_frac Up to date fractional configuration. 130 * @retval None 131 * @note A PLL update is requested only when the system clock is 132 * running on the PLL with a different configuration that the 133 * one required. 134 */ 135 void scm_pll_fractional_update(uint32_t pll_frac); 136 137 /** 138 * @brief Set the HSE clock to the requested frequency. 139 * @param user_id This parameter can be one of the following: 140 * @arg SCM_USER_APP 141 * @arg SCM_USER_LL_FW 142 * @param sysclockconfig This parameter can be one of the following: 143 * @arg HSE_16MHZ 144 * @arg HSE_32MHZ 145 * @arg SYS_PLL 146 * @retval None 147 */ 148 void scm_setsystemclock (scm_user_id_t user_id, scm_clockconfig_t sysclockconfig); 149 150 /** 151 * @brief Called each time the PLL is ready 152 * @param None 153 * @retval None 154 * @note This function is defined as weak in SCM module. 155 * Can be overridden by user. 156 */ 157 void scm_pllready(void); 158 159 /** 160 * @brief Configure the Flash and SRAMs wait cycle (when required for system clock source change) 161 * @param ws_lp_config: This parameter can be one of the following: 162 * @arg LP 163 * @arg RUN 164 * @arg HSE16 165 * @arg HSE32 166 * @arg PLL 167 * @retval None 168 */ 169 void scm_setwaitstates(const scm_ws_lp_t ws_lp_config); 170 171 /** 172 * @brief Notify the state of the Radio 173 * @param radio_state: This parameter can be one of the following: 174 * @arg SCM_RADIO_ACTIVE 175 * @arg SCM_RADIO_NOT_ACTIVE 176 * @retval None 177 */ 178 void scm_notifyradiostate(const scm_radio_state_t radio_state); 179 180 /** 181 * @brief SCM HSERDY interrupt handler. 182 * Switch system clock on HSE. 183 * @param None 184 * @retval None 185 */ 186 void scm_hserdy_isr(void); 187 188 /** 189 * @brief SCM PLLRDY interrupt handler. 190 * Switch system clock on PLL. 191 * @param None 192 * @retval None 193 */ 194 void scm_pllrdy_isr(void); 195 196 /* Exported functions - To be implemented by the user ------------------------- */ 197 198 /** 199 * @brief SCM HSI clock enable 200 * @details A weak version is implemented in the module sources. 201 * @details It can be overridden by user. 202 * @param None 203 * @retval None 204 */ 205 extern void SCM_HSI_CLK_ON(void); 206 207 /** 208 * @brief SCM HSI clock may be disabled when this function is called 209 * @details A weak version is implemented in the module sources. 210 * @details It can be overridden by user. 211 * @param None 212 * @retval None 213 */ 214 extern void SCM_HSI_CLK_OFF(void); 215 216 #else /* CFG_SCM_SUPPORTED */ 217 218 /* Unused empty functions */ 219 void scm_hserdy_isr(void); 220 void scm_pllrdy_isr(void); 221 222 #endif /* CFG_SCM_SUPPORTED */ 223 224 #endif /* SCM_H */ 225