Page 1 of 1

STM32F7 - Switch clock source after initialization

Posted: Mon Jan 15, 2018 11:17 am
by elagil
Hello,

I need to switch clock sources from internal oscillator to external after full initialization. I will have to use the PAL driver in internal oscillator mode, do some switching of pins and then go to external oscillator mode.

Is there an easy way (clock init function?) to switch to external clock source while running on the internal oscillator? I will keep the same peripheral and main clock, I only need to change a few PLL parameters and MUXes.

Thanks in advance,
Adrian

Re: STM32F7 - Switch clock source after initialization

Posted: Mon Jan 15, 2018 11:28 am
by Giovanni
Hi,

The clock initialization code is not that flexible, you need to switch manually to HSI and do your work, calling stm32_clock_init() again should work in order to return to the previous state assuming you de-initialized everything.

If you just operate on the clocks mux without stopping PLLs then you need just to switch the mux again in order to return to the previous situation.

Giovanni

Re: STM32F7 - Switch clock source after initialization

Posted: Mon Jan 15, 2018 3:14 pm
by steved
Giovanni wrote:Hi,

The clock initialization code is not that flexible, you need to switch manually to HSI and do your work, calling stm32_clock_init() again should work in order to return to the previous state assuming you de-initialized everything.

If you just operate on the clocks mux without stopping PLLs then you need just to switch the mux again in order to return to the previous situation.

Giovanni

I think OP needs to start in HSI, then move to HSE.
I've done this myself (not on the F7), by directly operating on the affected clock registers. A potential 'gotcha' is that (AFAIK) Chibi uses the configured SYSCLK frequency and so on in the calculation of other timings. I managed to avoid this potential problem by using the same SYSCLK frequency throughout - if it was actually slower on boot it didn't matter in my situation.

Re: STM32F7 - Switch clock source after initialization

Posted: Mon Jan 15, 2018 3:22 pm
by Giovanni
Hi,

If you need to run code before clock initialization just add an hook to the __early_init() function (in board.c) before the clock is initialized, perform your initializations there.

Giovanni