Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures 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 the SCG module.

The 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

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

The SCG driver provides APIs to set and get configuration registers. For example, to get the system clock configuration of the RUN mode, use the function CLOCK_HAL_GetSystemClockConfigInRun(). To set the system clock configuration of the VLPR mode, use the function CLOCK_HAL_SetSystemClockConfigInVlpr().

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

APIs for clock out selection

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

APIs for clock source configuration

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

This is an example to set up the clock source based on the SCG HAL APIs.

/* An example code that shows how to set up the system OSC.
scg_sys_osc_config_t config;
// Get default configuration.
CLOCK_HAL_GetSysOscDefaultConfig(&config);
// Modify according to board setting.
// ...
// Sets up the system OSC.
CLOCK_HAL_InitSysOsc(SCG_BASE, &config);
// De-initializes the system OSC.
CLOCK_HAL_DeinitSysOsc(SCG_BASE);

Because some configurations of the clock source can only be changed when the clock source is disabled, the function CLOCK_HAL_InitXxx disables the clock source, re-configures and enables it. As a result, before using the CLOCK_HAL_InitXxx, ensure that the clock source is not used.