AnsweredAssumed Answered

Proper way to switch to HSE

Question asked by kikugawa.sho on Apr 5, 2012
Latest reply on Apr 9, 2012 by Clive One
My application calls for using an external oscillator (not a crystal) as a clock source. To test this, I have an arbitrary function generator outputting a 50% duty cycle square wave of the expected clock rate. The MCU is supposed to go to sleep, then upon wake up, switch to the HSE as fast as possible.

However, in tests, I find that switching to the HSE is always taking somewhere around 2.5ms. The function generator is always on, so I was expecting sub millisecond switching. Here's what I'm doing:
  1. On wake up, set the HSEON bit in the RCC_CR register (using the RCC_HSEConfig(ENABLE); function from the standard periph library)
  3. Do a spin-lock while loop until HSE is ready.    
    1. The reason why I do a spin-lock is because the system clock is going to drive a PWM immediately afterwards, so the MCU cannot go ahead and drive it, otherwise the timing will be off.

Is there something I'm doing wrong that's causing up to 2.5ms delay? I recall when I had a regular crystal oscillator, it was adding about 1ms or so.

EDIT: I found the args for RCC_HSEConfig() are supposed to be RCC_HSE_ON or RCC_HSE_Bypass, and I'm not sure what ENABLE is defined as.