HAL_RCC_OscConfig 花费的时间太长(约 170 μS),我需要它在从 STOP 唤醒时小于 50 μS

HAL_RCC_OscConfig takes too long (appx 170 μS), I need it to be <50 μS when waking from STOP

在 NUCLEO-L053R8 板上开发 STM32L053R8。

我们有一个系统 "wakes" 每 200 μS 左右从睡眠状态开始,执行少量工作然后返回睡眠状态(停止模式)。 理想情况下,我希望在 50 μS 以内从停止状态唤醒。 HAL_RCC_OscConfig() 函数大约需要 170 μS,这使得这项工作变得毫无意义。

据我所知,大部分时间都花在了 PLL 配置上,尤其是在重新启用 PLL(大约 98 μS)之后的 while 循环 ("Wait till PLL is ready")。

/* Configure the main PLL clock source, multiplication and division factors. */
__HAL_RCC_PLL_CONFIG(RCC_OscInitStruct->PLL.PLLSource,
                     RCC_OscInitStruct->PLL.PLLMUL,
                     RCC_OscInitStruct->PLL.PLLDIV);
/* Enable the main PLL. */
__HAL_RCC_PLL_ENABLE();

/* Get timeout */
tickstart = HAL_GetTick();

/* Wait till PLL is ready */  
while(__HAL_RCC_GET_FLAG(RCC_FLAG_PLLRDY) == RESET)
{
  if((HAL_GetTick() - tickstart ) > RCC_PLL_TIMEOUT_VALUE)
  {
    return HAL_TIMEOUT;
  }      
}  

是否有任何方法可以在 50 μS 内从 STOP 模式唤醒并返回全速 HSI? 从 STOP 唤醒时设置时钟的最有效方法是什么?

目前我使用PWR_STOP例子中规定的方法如下:

/* Enter Stop Mode */
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

/* Stop interrupt that woke us up */
int ret = HAL_LPTIM_TimeOut_Stop_IT(&LptimHandle);
SystemDisableWakeupCounter();

/* Configures system clock after wake-up from STOP: enable HSI, PLL and select
PLL as system clock source (HSI and PLL are disabled automatically in STOP mode) */
SystemClockConfig_STOP();

SystemClockConfig_STOP() 的调用依次调用 SystemClock_Config(),它配置时钟并在 HAL_RCC_OscConfig(&RCC_OscInitStruct).

中包含这个长延迟

非常感谢您提供的任何帮助。

好吧,datasheet 说 PLL 锁定最多需要 160 微秒,所以只要您尝试使用 PLL,延迟就会存在。

你需要 PLL 吗?

您可以将 RCC 配置为在 16 MHz 时已经 运行 使用 HSI 唤醒(参见 RCC_CFGR_STOPWUCK 位)。您的速度只有一半,但它会在 6 us 内达到 运行。

目前不知道你的PLL源是什么,推荐HSI16。全部来自 reference manual.

The HSI16 clock signal is generated from an internal 16 MHz RC oscillator. It can be used directly as a system clock or as PLL input.

The HSI16 clock can be used after wake-up from the Stop low-power mode, this ensure a smaller wake-up time than a wake-up using MSI clock.


如果可以允许稍高的功耗,请不要禁用内部调节器。这是一个妥协:更快唤醒消耗更高或更慢同时节省更多能量,决定哪个更重要。

When exiting Stop mode by issuing an interrupt or a wakeup event, the MSI or HSI16 RC oscillator is selected as system clock depending the bit STOPWUCK in the RCC_CFGR register.

When the voltage regulator operates in low-power mode, an additional startup delay is incurred when waking up from Stop mode. By keeping the internal regulator ON during Stop mode, the consumption is higher although the startup time is reduced.


现在我想使用 PLL 是必须的,但我担心除了上面提到的之外你不能对启动时间做太多事情。 PLL 需要一定的时间来锁定输入参考时钟频率。但首先输入频率必须稳定(这就是为什么推荐使用HSI16)。

您可以使用中断代替阻塞等待(while 循环)。

An interrupt can be generated when the PLL is ready if enabled in the RCC_CIER register (see Section 7.3.5).

并且当PLL锁定时你可以在16MHz上做一些任务,需要全速的任务可以在接收到中断时开始(在ISR中完成时钟配置)。