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:
- On wake up, set the HSEON bit in the RCC_CR register (using the RCC_HSEConfig(ENABLE); function from the standard periph library)
- Do a spin-lock while loop until HSE is ready.
- 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.