Kinetis MCG

Implementation of the Kinetis Multipurpose Clock Generator (MCG) driver.

Please add mcg.h in cpu_conf.h and MCG configuration to periph_conf.h

The configuration consists of the clock_config struct (clock_config_t) and two macros boards/z1/include/periph_conf.h::CLOCK_CORECLOCK, mcg.h::CLOCK_BUSCLOCK. The two macros are used by other periph driver configurations to tell the driver what value the module clock is running at.

State transition map

The driver will automatically move step by step through the map if the requested mode is not a direct neighbor of the current mode.

MCG Configuration Examples (for periph_conf.h)

Example for PEE Mode with an 8 MHz crystal connected to XTAL0/EXTAL0

The resulting PLL output frequency will be 60 MHz, the core will be running at the full PLL output frequency.

Example for FEE Mode, 32.768 kHz crystal connected to RTC

The resulting FLL output frequency will be circa 72 MHz, the core will be running at the full FLL output frequency.

Example for PEE Mode with an 8 MHz crystal connected to XTAL0/EXTAL0

The resulting PLL output frequency will be 60 MHz, the core will be running at the full PLL output frequency.

Example for FEE Mode, 32.768 kHz crystal connected to RTC

The resulting FLL output frequency will be circa 72 MHz, the core will be running at the full FLL output frequency.

int kinetis_mcg_set_mode(kinetis/include/periph_cpu.h::kinetis_mcg_mode_t mode)

Switch the MCG to the specified clocking mode.

Depending on the current clocking mode, this function may step through several other clocking modes in order to be able to reach the target mode.

Parameters

mode:Target mode

Return values

  • 0 on success
  • <0 on error
void kinetis_mcg_init(void)

Initialize the MCG.

The configuration is found in the clock_config struct defined in periph_conf.h

CLOCK_CORECLOCK

Core clock frequency, used by the ARM core and certain hardware modules in Kinetis CPUs.

1
(MCGOUTCLK)

The clock is derived from the MCG output clock divided by an integer divisor, which is controlled by the kinetis/include/periph_cpu.h::clock_config_t::clkdiv1 settings

CLOCK_BUSCLOCK

Bus clock frequency, used by several hardware modules in Kinetis CPUs.

1
(CLOCK_CORECLOCK / x)

The clock is derived from the MCG output clock divided by an integer divisor, which is controlled by the kinetis/include/periph_cpu.h::clock_config_t::clkdiv1 settings