STM32F7 - Switch clock source after initialization

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: barthess, RoccoMarco

elagil
Posts: 23
Joined: Tue Sep 19, 2017 7:38 am
Has thanked: 1 time
Been thanked: 1 time

STM32F7 - Switch clock source after initialization

Postby elagil » Mon Jan 15, 2018 11:17 am

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

User avatar
Giovanni
Site Admin
Posts: 10574
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 268 times
Been thanked: 231 times
Contact:

Re: STM32F7 - Switch clock source after initialization

Postby Giovanni » Mon Jan 15, 2018 11:28 am

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

steved
Posts: 487
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 3 times
Been thanked: 39 times

Re: STM32F7 - Switch clock source after initialization

Postby steved » Mon Jan 15, 2018 3:14 pm

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.

User avatar
Giovanni
Site Admin
Posts: 10574
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 268 times
Been thanked: 231 times
Contact:

Re: STM32F7 - Switch clock source after initialization

Postby Giovanni » Mon Jan 15, 2018 3:22 pm

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


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 4 guests