This is the quick start guide for the System Clock Management service, with step-by-step instructions on how to configure and use the service for specific use cases.
System Clock Management use cases
Basic usage of the System Clock Management service
This section will present a basic use case for the System Clock Management service. This use case will configure the main system clock to 48MHz, using an internal DFLL module to multiply the frequency of a crystal attached to the microcontroller. The peripheral bus clocks are scaled down from the speed of the main system clock.
Prerequisites
Initialization code
Add to the application initialization code:
Workflow
- Configure the system clocks according to the settings in conf_clock.h:
Example code
Add or uncomment the following in your conf_clock.h header file, commenting out all other definitions of the same symbol(s):
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_DFLL0
#define CONFIG_DFLL0_SOURCE GENCLK_SRC_OSC32K
#define CONFIG_DFLL0_FREQ 48000000UL
#define CONFIG_DFLL0_MUL (CONFIG_DFLL0_FREQ / BOARD_OSC32_HZ)
#define CONFIG_DFLL0_DIV 1
#define CONFIG_SYSCLK_CPU_DIV 0
#define CONFIG_SYSCLK_PBA_DIV 1
#define CONFIG_SYSCLK_PBB_DIV 1
#define CONFIG_SYSCLK_PBC_DIV 1
#define CONFIG_SYSCLK_PBD_DIV 1
Workflow
- Configure the main system clock to use the output of the DFLL0 module as its source:
#define CONFIG_SYSCLK_SOURCE SYSCLK_SRC_DFLL0
- Configure the DFLL0 module to use external crystal oscillator OSC0 as its source:
#define CONFIG_DFLL0_SOURCE GENCLK_SRC_OSC32K
- Configure the DFLL0 module to multiply the external oscillator OSC0 frequency up to 48MHz:
#define CONFIG_DFLL0_FREQ 48000000UL
#define CONFIG_DFLL0_MUL (CONFIG_DFLL0_FREQ / BOARD_OSC32_HZ)
#define CONFIG_DFLL0_DIV 1
- Note
- For user boards,
BOARD_OSC0_HZ
should be defined in the board conf_board.h
configuration file as the frequency of the crystal attached to OSC0.
- Configure the main clock to run at the full 48MHz, scale the peripheral busses to run at one half (2 to the power of 1) of the system clock speed:
#define CONFIG_SYSCLK_CPU_DIV 0
#define CONFIG_SYSCLK_PBA_DIV 1
#define CONFIG_SYSCLK_PBB_DIV 1
#define CONFIG_SYSCLK_PBC_DIV 1
#define CONFIG_SYSCLK_PBD_DIV 1
- Note
- Some dividers are powers of two, while others are integer division factors. Refer to the formulas in the conf_clock.h template commented above each division define.