Page 1 of 1

dynamic clocks

Posted: Sat Mar 15, 2025 1:23 pm
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?

Re: dynamic clocks

Posted: Sat Mar 15, 2025 3:19 pm
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

Re: dynamic clocks

Posted: Sat Mar 15, 2025 4:51 pm
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

Re: dynamic clocks

Posted: Sat Mar 15, 2025 5:23 pm
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

Re: dynamic clocks

Posted: Sat Mar 15, 2025 6:00 pm
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

Re: dynamic clocks

Posted: Sat Mar 15, 2025 7:49 pm
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