title: HAL_RCC_OscConfig takes too long (appx 170 μS), I need it to be <50 μS when waking from STOP
body: <p>Development for STM32L053R8 on NUCLEO-L053R8 board.</p>
  
  <p>We have a system which "wakes" from sleep every 200 μS or so, does a small amount of work then goes back to sleep (Stop mode).
  Ideally I'd like to wake from STOP in under 50 μS.
  The <code>HAL_RCC_OscConfig()</code> function takes around 170 μS which renders this effort pointless.</p>
  
  <p>From what I can see the majority of time is spent with the PLL Configuration, in particular the while loop ("Wait till PLL is ready") which follows the re-enablement of the PLL (about 98 μS).</p>
  
  <pre><code>/* Configure the main PLL clock source, multiplication and division factors. */
  __HAL_RCC_PLL_CONFIG(RCC_OscInitStruct-&gt;PLL.PLLSource,
                       RCC_OscInitStruct-&gt;PLL.PLLMUL,
                       RCC_OscInitStruct-&gt;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 ) &gt; RCC_PLL_TIMEOUT_VALUE)
    {
      return HAL_TIMEOUT;
    }      
  }  
  </code></pre>
  
  <p>Are there any ways to wake from STOP mode and get back to full speed HSI in under 50 μS?
  What is the most efficient method to set the clocks when waking from STOP?</p>
  
  <p>Currently I use the method prescribed in the PWR_STOP example which is as follows:</p>
  
  <pre><code>/* 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(&amp;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();
  </code></pre>
  
  <p>The call to <code>SystemClockConfig_STOP()</code> in turn calls <code>SystemClock_Config(</code>) which configures the clocks and includes this long delay in <code>HAL_RCC_OscConfig(&amp;RCC_OscInitStruct)</code>.</p>
  
  <p>Many thanks in advance for any assistance offered.</p>