cancel
Showing results for 
Search instead for 
Did you mean: 

How do I switch PLLSource once it is running?

anonymous.8
Senior II
Posted on December 07, 2016 at 22:19

Hi, I want to start off my STM32F745VET6 running on the PLL sourced from the 16MHZ HSI oscillator. I need to run some I2C code to initialize an external multi-output high accuracy clock generator chip where one of its outputs feeds a high accuracy 16MHz clock into the HSE input pin. I then want to switch over the PLL source from the HSI source to the HSE source. But I can't do that while the PLL is running so if I disable it first in order to switch the source and then re-enable it again, what happens to the system clock and the core while the PLL is disabled? Which clock runs the chip in the mean time?

BTW, I hate HAL to the death - it is pure bloatware - I am using my own bare metal code and don't use either HAL or STD_PERIPH.

Thanks.

6 REPLIES 6
Posted on December 07, 2016 at 22:36

Well at a hardware level you get to select the HSI, HSE, or PLL as the source clock for the CPU. So you pick which clock you want, and then you can turn the PLL off, change the settings for the PLL, turn it on, wait for it to lock, and then select PLL as the clock source.

If you want to change the gearing on the fly, do so at the AHB/APB level (I know that wasn't the question, but it is how to dynamically change speed)

Can you do the external clock initialization at 16 MHz?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
anonymous.8
Senior II
Posted on December 07, 2016 at 23:20

Clive, thanks. I don't see why I can't run SYSCLK at 16MHz off of the HSI clock to do the external clock generator setup to start with. All I need to do is set up some GPIO pins and Initialize the I2C peripheral. Then once the external clock gen. is running I can switch the whole system to run off of the PLL. I may need to change the I2C TIMINGR register value to accommodate a change in the I2C peripheral clock.

One thing I will say that is nice about the STMCube thingy - that is STM32CubeMX tool. It is very handy to check the pinouts and peripherals in use and to visualize the clock configuration and to estimate power consumption. Its initialization code is not directly usable for me because I don't use the HAL layer, but some of the register values can be used in my own code.

Jeroen3
Senior
Posted on December 08, 2016 at 07:51

I think you don't have much choice, you can run on HSI with PLL first to do some stuff. (if you need rom checksum for example) Then switch back to HSI until HSE with PLL is ready.

You can probably utilize the RCC interrupt for this, looks like a great application for some

https://en.wikipedia.org/wiki/Finite-state_machine

.
anonymous.8
Senior II
Posted on December 08, 2016 at 17:49

Thanks to all who have answered. I think I was making it seem more complex than I needed. I now realize I don't have to use the PLL at all for the early on stuff such as initializing the GPIO pins, the I2C interface and the external clock generator chip. That can all be done at 16MHz using HSI as the clock source. I can wait until the external clock chip has stabilised by requesting its status over I2C and then start-up the STM32F745VET6 's PLL and then wait for its PLL to stabilize before switching SYSCLK etc. to the PLL for full speed operation. I don't even have to change the timing of the I2C module as it can remain clocked by the 16MHz HSI since absolute accuracy of the I2C clock source is not required, it's a synchronous protocol after all.

Seb
ST Employee
Posted on December 10, 2016 at 18:09

Great! If the external clock source gets into trouble, there should be a safety option where the internal clock falls back to HSI when HSE is having issues. Also, for information, the STM32L4 has a new MSI feature to generate high frequency from 32kHz (LSI or LSE) sometime yielding a lower power consumption. Good luck!

shingadaddy
Senior
Posted on December 10, 2016 at 18:33

That L4 / MSI / 32.768 clock trick seems to work for USB for me so far too. Here's another way to switch the clocks.

https://www.youtube.com/watch?v=hIkNY5xjy5k