Stm32L0 – can I use LSE clock for 1ms tick and use HSI for systick

clock-speedstm32

I am using STM32L051, our task has two requirements for clock management:

  1. Need to be running under 16Mhz or higher frequency (thus we use the MSI/HSI for Systick) for fast task processing.
  2. Need a higher precision clock source (50ppm 32khz LSE is ok; and our board has an external 20ppm 32khz crystal) to limit the clock deviation to about 100ms per 30minutes.

How can I configure the clock system to use both the MSI/HSI (for Systick) and external 32khz crystal (for lower clock deviation)?

I have searched the datasheet and google a lot, however didn't find a solution. I am not familiar with MCU development. Please kindly refer me to the datasheet section (several keyword is ok) or cortex-driver API for further research, thanks!

Best Answer

Of course, you able to use two clock sources. Read Reference manual (RM0377, http://www.st.com/web/en/resource/technical/document/reference_manual/DM00108282.pdf), section Reset and clock controls.

Core and peripherals will work with HSI, multiplied by PLL (if you want work on frequency, not equal to 16MHz), and RTC will be clocked by low-speed crystal.

Also, if you don't needed power saving features, you may use only one high-speed crystal (8 MHz, for example), and feed clock via PLL to core and via prescaler - to RTC. You may find details in ref.manual, figure 'Clock tree (STM32F03x and STM32F05x devices)'.

PS you may use RTC wakeup interrupt instead of systick timer. This will provide more accurate period measurements.