L476 clocks

tree
Four different clock sources can be used to drive the system clock (SYSCLK):
* MSI (multispeed internal) RC oscillator clock
* HSI16 (high speed internal) 16 MHz RC oscillator clock
* HSE oscillator clock, from 4 to 48 MHz
* PLL clock

The MSI clock is used as system clock source after startup from Reset, configured at 4 MHz.

The STM32L476 has the following additional clock sources:
* 32 kHz low speed internal RC (LSI RC) which drives the independent watchdog and
optionally the RTC used for Auto-wakeup from Stop and Standby modes.
* 32.768 kHz low speed external crystal (LSE crystal) which optionally drives the real-
time clock (RTCCLK).
#define RCC_ICSCR MMIO32(RCC_BASE + 0x04)

/** Clock Configuration register */

MSI clock

Twelve frequencies are available: 100 kHz, 200 kHz, 400 kHz, 800 kHz, 1 MHz, 2 MHz, 4 MHz (default value), 8 MHz, 16 MHz, 24 MHz, 32 MHz and 48 MHz.

MSI Range after standby values
RCC_CSR_MSIRANGE_1MHZ
RCC_CSR_MSIRANGE_2MHZ
RCC_CSR_MSIRANGE_4MHZ
RCC_CSR_MSIRANGE_8MHZ

Use two registers; * RCC_CR at RCC_BASE + 0x00 * RCC_CFGR at RCC_BASE + 0x08

RCC clock control register (RCC_CR)

clock1
Address offset: 0x00
Reset value: 0x0000 0063
reset value –> bit 0000 0000 0110 0011
bit 0 MSION: after reset, MSION is enabled
bit 1 MSIRDY: MSI clock ready flag is ready
bits 7:4 MSIRANGE[3:0]: MSI clock ranges
0110: range 6 around 4 MHz (reset value)

means that after reset the system clock is MSI at 4 MHz.

Clock configuration register (RCC_CFGR) Address offset: 0x08 Reset value: 0x0000 0000

MSI clock
rcc_set_msi_range(RCC_CR_MSIRANGE_48MHZ);  // 11   1011

rcc_osc_on(RCC_MSI);
rcc_wait_for_osc_ready(RCC_MSI);

// select MSI as SYSCLK source
/* SW: System clock switch */
rcc_set_sysclk_source(RCC_CFGR_SW_MSI);
rcc_wait_for_sysclk_status(RCC_MSI);
bits 3:2 SWS[1:0]: system clock switch status
00: MSI oscillator used as system clock
01: HSI16 oscillator used as system clock
10: HSE used as system clock
11: PLL used as system clock

|Bits 1:0 SW[1:0]: System clock switch |00: MSI selected as system clock |01: HSI16 selected as system clock | 10: HSE selected as system clock | 11: PLL selected as system clock

MSI PLL

Control/status register (RCC_CSR) Address: 0x94 Reset value: 0x0C00 0600, reset by system Reset, except reset flags by power Reset only.

clock1