catie-aq / zephyr_zest-core-stm32l4a6rg

Zest_Core_STM32L4A6RG custom target for Zephyr OS
Apache License 2.0
0 stars 0 forks source link

Use MSI oscillator instead of HSI #4

Open Copper-Bot opened 8 months ago

Copper-Bot commented 8 months ago

HSI oscillator is actually used as main clock source by PLL mux.

But if the user needs to use the USB, it is not recommended to use the HSI as it is not precise enough and stable to achieve proper 48 Mhz USB operation.

A solution would be to use external HSE, but none can be mounted in zest cores.

Another solution is to use internal MSI RC clock. Thanks to the mounted LSE (Low Speed External) clock of 32.768kHz, "the MSI frequency can be automatically trimmed by hardware to reach an accuracy better than ±0.25 %". This is called "Auto calibration [by PLL]" and "must be enabled to reach a stable 48 MHz" for USB operation.

At 30 °C, the HSI16 oscillator has an accuracy of ± 0.5 % and the MSI oscillator has an accuracy of ± 0.6 %. So, by using LSE clock, MSI can achieve an accuracy of ± 0.25 %, better than normal HSI operation.

See these documents for more information:

By using the MSI clock, we can provide both stable sources for USB 48 MHz clock and SYSCLK max speed 80 Mhz clock (using PLL).

Default MSI value is 4MHz (range 6). By keeping this value, we can assure:

The MSI must be set in PLL-mode by setting the MSIPLLEN bit in the Clock control register (RCC_CR) so it can automatically calibrate itself thanks to the LSE.

Proposed clock configuration for the STM32L4A6RGT6: image

Side Note (RDE): LSE drive capability (LSEDRV) should be increased if LSE do not start (because of STM32 internal problems with the drive amplifier).

Copper-Bot commented 8 months ago

It seems that the current implementation of pll clock by Zephyr (for st,stm32l4) support only main PLL for now.

EDIT: MSI driven PLL with LSE calibration seems to be supported