本帖最后由 Sam131208 于 2025-2-17 09:26 编辑
初始化时,时钟设置为PLL32M, 时钟源为irc16m. 进入了深度睡眠1后唤醒,频率变为了16mhz. 是否还需要其它设置才可以维持PLL设定?
测试方法为:配置PA8输出系统时钟, 进入深度睡眠1, 唤醒后频率成为16mhz.
下面是PLL程序:
- static void switch_system_clock_to_32m_irc16m(void)
- {
- uint32_t timeout = 0U;
- uint32_t stab_flag = 0U;
- /* select IRC16M as system clock source, deinitialize the RCU */
- rcu_system_clock_source_config(RCU_CKSYSSRC_IRC16M);
- rcu_deinit();
- /* enable IRC16M */
- RCU_CTL |= RCU_CTL_IRC16MEN;
- /* wait until IRC16M is stable or the startup time is longer than IRC16M_STARTUP_TIMEOUT */
- do {
- timeout++;
- stab_flag = (RCU_CTL & RCU_CTL_IRC16MSTB);
- } while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
- /* if fail */
- if(0U == (RCU_CTL & RCU_CTL_IRC16MSTB)) {
- while(1) {
- }
- }
- /* set the wait state counter value */
- FMC_WS = (FMC_WS & (~FMC_WS_WSCNT)) | FMC_WAIT_STATE_0;
- /* AHB = SYSCLK */
- RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
- /* APB2 = AHB */
- RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
- /* APB1 = AHB/2 */
- RCU_CFG0 |= RCU_APB1_CKAHB_DIV1;
- /* PLL = (IRC16M/2) * 4 = 32 MHz */
- RCU_CFG1 &= ~(RCU_CFG1_PREDV);
- RCU_CFG1 |= RCU_PLL_PREDV2;
- RCU_CFG0 &= ~(RCU_CFG0_PLLSEL | RCU_CFG0_PLLMF);
- RCU_CFG0 |= (RCU_PLLSRC_IRC16M | RCU_PLL_MUL4);
- /* enable PLL */
- RCU_CTL |= RCU_CTL_PLLEN;
- /* wait until PLL is stable */
- while(0U == (RCU_CTL & RCU_CTL_PLLSTB)) {
- }
- /* select PLL as system clock */
- RCU_CFG0 &= ~RCU_CFG0_SCS;
- RCU_CFG0 |= RCU_CKSYSSRC_PLL;
- /* wait until PLL is selected as system clock */
- while(0U == (RCU_CFG0 & RCU_SCSS_PLL)) {
- }
- }
附件为测试代码。 如果设置为PLL时钟输出,进入深度睡眠后,时钟输出就停止了。
|