Modifying clock configurations on KW2xD

Document created by Gerardo Rodríguez Employee on Dec 8, 2016Last modified by ebiz_ws_prod on Aug 6, 2018
Version 8Show Document
  • View in full screen mode

By default the clock configuration on the KW2xD demos is set to PLL Engaged External (PEE). In this mode the system clock is derived from the output of the PLL and controlled by an external reference clock. The modem provides a programmable clock source output CLK_OUT that can be used as the external reference clock for the PLL. In the Figure 1 we can see that the CLK_OUT modem signal is internally connected to EXTAL0 in the MCU.


The CLK_OUT output frequency is controlled by programming the modem 3-bit field CLK_OUT_DIV [2:0] in the CLK_OUT_CTRL Register. The default frequency is either 32.787 kHz or 4 MHz depending on the state of the modem GPIO5 at reset determined by the MCU. See section 4.4.2 and 5.6.2 from the MKW2xD Reference Manual for more information on the clock output feature.

  • If the GPIO5 modem pin is low upon POR, then the frequency will be 4 MHz.
  • If this GPIO5 modem pin is high upon POR, then the frequency will be 32.78689 kHz.


In the KW2xD demos, the GPIO5 (PTC0) is held low during the modem reset so the CLK_OUT has a frequency of 4MHz. The clock configuration structure g_defaultClockConfigRun is defined in board.c.

Figure 1. Internal Functional Interconnects


In this example project, another clock configuration will be added to the Connectivity Test Project: FLL Engaged Internal (FEI). In this mode, the system clock is derived from the FLL clock that is controlled by the 32kHz Internal reference clock.


In FEI mode the MCU doesn’t need the clock source output CLK_OUT from the modem, so we can disable the radio’s clock output and then set the radio to Hibernate to save power when we are not using the radio.


If the low-power module from the connectivity framework is used to go to a low-power mode, the clock configuration is changed automatically when entering a sleep mode (See the Connectivity Framework Reference Manual for more information about the low-power library).


System Requirements

Application Description

The clock configuration can be changed with shortcuts on the serial console:

  • Press “c” to use the PEE clock configuration (default).
  • Press “v” to use the FEI clock configuration and set the radio to Autodoze.
  • Press “b” to use the FEI clock configuration and set the radio to Hibernate.


You must be in the main menu in order to change the radio mode, the mode automatically changes to Autodoze when entering a test menu.


Hibernate mode can only be changed when in FEI mode. This is because in hibernate the radio disables the CLK_OUT and the PEE configuration needs this clock.


Current Measurements

The following measurements were done in a TWR-KW24D256 through J2 5-6 to measure the radio current.

Table 1. Radio Current Measurements

Clock mode/Radio modeRadio Current




Code Modifications

The following modifications to the source files were made:

  • \boards\twrkw24d512\Board.c
    Added clock user configuration
    Added array of clock configs and configuration struct for clock callback


  • \boards\twrkw24d512\Board.h
    Include for fsl_clock_manager.h
    Declaration of clock callback and configuration array used in CLOCK_SYS_Init() function.


  • \boards\twrkw24d512\Hardware_init.c
    Added calibration code after BOARD_ClockInit(), this is to calibrate internal clock using the bus clock.


  • \examples\smac\Connectivity_Test\common\Connectivity_TestApp.c
    Initialize the clock manager.
    Disable PTC0 because it is only used at modem reset to select the CLK_OUT default frequency (4MHz).
    Return clock configuration on idle state.
    Prepare radio to go to Autodoze when entering a test menu.


  • \examples\smac\Connectivity_Test\twrkw24d512\common\Connectivity_Test_Platform.c
    Changed length of the lines to be erased in PrintTestParameters() from 65 to 80
    Added clock config and radio mode to be printed in the test parameters.
    Added the cases in the shortcut parser to change the clock and radio configuration with the keys “c”, “v” and “b”.
    Added functions at end of file (Explained in the next section).


  • \examples\smac\Connectivity_Test\twrkw24d512\common\Connectivity_Test_Platform.h
    Macros for the clock and radio modes.
    Function prototypes from the source file.


  • \examples\smac\Connectivity_Test\twrkw24d512\common\ConnectivityMenus.c
    Shortcuts descriptions.


The modified source files can be found attached to this document.


Functions added

The functions PWRLib_Radio_Enter_Hibernate() and PWRLib_Radio_Enter_AutoDoze() were taken from the file PWRLib.c located at <Connectivity_Software_Path>\ConnSw\framework\LowPower\Source\KW2xD. The PWRLib.c file is part of the low-power library from the connectivity framework.


The Clock_Callback() function was implemented to handle when the clock configuration is updated. Inside the function there is a case to handle before and after the clock configuration is changed. Before the clock configuration is changed, the UART clock is disabled and if the clock configuration is PEE, the radio is set to AutoDoze and the CLK_OUT is enabled. After the clock configuration has changed, the Timer module is notified that the clock has changed, the UART is re-initialized and if the clock configuration is FEI, the CLK_OUT is disabled. This behavior is shown in Figure 2.

Figure 2. Clock callback diagram


The prepareRadio() function is used when entering a test mode to make sure the radio is set to AutoDoze in case it was in hibernate.

The restoreRadio() function is used when leaving the test menu and going to hibernate if it was previously set.

2 people found this helpful