Kinetis SDK v.1.2 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages

This section describes the programming interface of the SCG HAL driver. The SCG HAL driver configures the SCG (System Clock Generator). It handles calibration, initialization, and configuration of SCG module.

SCG driver provides three kinds of APIs:

  1. APIs for MCU system clock.
  2. APIs for clock out selection.
  3. APIs for clock source configuration, including system OSC, slow IRC, fast IRC and system PLL.

APIs for MCU system clock

MCU system clock configuration includes clock source and dividers. There are dedicated control registers for RUN mode, VLPR mode and HSRUN mode. When MCU switches to new power mode, the configuration for corresponding mode will be used.

SCG driver provides the APIs to set and get this configure registers, for example, to get the system clock configuration of RUN mode, please use the function CLOCK_HAL_GetSystemClockConfigInRun(), to set the system clock configuration of VLPR mode, please use the function CLOCK_HAL_SetSystemClockConfigInVlpr().

Besides these APIs, SCG HAL driver also provides CLOCK_HAL_GetSystemClockFreq() to get the system clock output frequency.

APIs for clock out selection

For SCG CLKOUT, SCG HAL driver provides CLOCK_HAL_GetClkOutSel() and CLOCK_HAL_SetClkOutSel() to get and set configuration.

APIs for clock source configuration

SCG has four clock sources, system OSC, system PLL, fast IRC and slow IRC. For each clock source, SCG driver provides such APIs:

There is an example shows how to setup the clock source base on SCG HAL APIs.

/* Example code for how to setup system OSC. */
scg_sys_osc_config_t config;
// Get default configuration.
CLOCK_HAL_GetSysOscDefaultConfig(&config);
// Modify according to board setting.
// ...
// Setup system OSC.
CLOCK_HAL_InitSysOsc(SCG_BASE, &config);
// De-init system OSC.
CLOCK_HAL_DeinitSysOsc(SCG_BASE);

Because some configurations of the clock source could only be changed when the clock source is disabled, so the function CLOCK_HAL_InitXxx will disable the clock source, then re-configure it and enable it. As a result, before CLOCK_HAL_InitXxx, please make sure the clock source is not used.