dynamic clocks

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

Moderator: RoccoMarco

Post Reply
geoffrey.brown
Posts: 122
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 18 times

dynamic clocks

Post by geoffrey.brown »

I'm interested in support for changing the system clock dynamically (esp. in the stm32l4) it appears this is a topic that has been considered before and I found the following hal define: HAL_LLD_USE_CLOCK_MANAGEMENT, but I'm not sure if changing the system clock is supported either in the stm32l4 or at all.

My application (sub-gram data loggers of song birds, or tags) has two "modes" -- connected through swd to a configuration/download application, and running free. The swd connect happens under reset, so there's an opportunity at that point to choose a clock configuration before initialization begins (i.e by checking a value set by the application) and it might be simpler than the general case. In my earlier tags, clock speed wasn't really an issue, but newer tags have an external flash download speeds are an issue and might be improved by faster SPI speeds.

Thoughts? Suggestions?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: dynamic clocks

Post by Giovanni »

Hi,

Dynamic clock switching is implemented on the L4+ but not on the L4. Implementing the new API is a significant effort and has not be back-ported to older devices.

Said that, L4 is very similar to L4+, you may try to back-port L4+ hal_lld.c/h to L4 and fix the few differences.

The new system allow to switch clocks among multiple configurations, there are 2 standard configurations:
1) Post-reset, brings clocks in a post-reset state.
2) Default, uses mcuconf.h settings, this one is applied on halInit().

In addition you can add your own configurations and switch freely at runtime but keep in mind that clock peripherals will also change, in that case you need to restart the drivers with new configurations, it is not 100% transparent unless for those peripherals clocked directly by oscillators or independent clocks.

Giovanni
geoffrey.brown
Posts: 122
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 18 times

Re: dynamic clocks

Post by geoffrey.brown »

In my case, it might be enough to choose between two "halinit" configurations since the application monitor has control before halinit. With so many things determined by compile time constants, I could use a bit of guidance on how that might be accomplished.

Geoffrey
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: dynamic clocks

Post by Giovanni »

I don't see this easier than using dynamic switching.

You could skip clock initialization by HAL and program RCC using custom code but then all drivers would work using wrong settings.

Giovanni
geoffrey.brown
Posts: 122
Joined: Thu May 07, 2015 9:47 pm
Has thanked: 3 times
Been thanked: 18 times

Re: dynamic clocks

Post by geoffrey.brown »

Thanks for the input. At least L4 and L4+ appear to use the same RCC definitions. I'll have to think about this some more.
Geoffrey
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: dynamic clocks

Post by Giovanni »

Not exactly the same, the L4+ has one M divider for each PLL, L4 has one M divider for all PLLs, this is the main difference.

Giovanni
Post Reply